473,387 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem inserting a function - Easy question

Hi !!!

I have the following php code

<?php
$db = mysql_connect("1", user, password)
or die ("canīt connect");
mysql_select_db(efemerides,$db);
mysql_close();
?>

I receive the error "canīt connect". Right beacuse "1" is not my
server.

Then I insert a function in the code and I do not receive the "canīt
connect" error. It seems that when I insert the function in the PHP
doesnīt work as it should

<?php
$db = mysql_connect("1", user, password)
or die ("no se ha podido conectar");
mysql_select_db(efemerides,$db);
function quitar($mensaje)
{
$mensaje = str_replace("<","<",$mensaje);
$mensaje = str_replace(">",">",$mensaje);
$mensaje = str_replace("\'","'",$mensaje);
$mensaje = str_replace('\"',""",$mensaje);
$mensaje = str_replace("\\\\","\",$mensaje);
return $mensaje;
}
mysql_close();
?>

Any suggestion?

Regards!

Ezequiel

Feb 4 '07 #1
2 1384
Rik
zek2005 <es*******@gmail.comwrote:
Hi !!!
Hello !!!
I have the following php code

<?php
$db = mysql_connect("1", user, password)
or die ("canÂīt connect");
mysql_select_db(efemerides,$db);
mysql_close();
?>

I receive the error "canÂīt connect". Right beacuse "1" is not my
server.

Then I insert a function in the code and I do not receive the "canÂīt
connect" error. It seems that when I insert the function in the PHP
doesnÂīt work as it should
$mensaje = str_replace('\"',""",$mensaje);
This will result in a parse error, preventing the script from ever
executing (which you would know if you had display_errors on, which is
very handy in development).

Change the line to the following and you'll get the expected behaviour:
$mensaje = str_replace('\"','"',$mensaje);
--
Rik Wasmus*
Feb 4 '07 #2
On Sun, 04 Feb 2007 07:22:17 -0800, zek2005 <es*******@gmail.comwrote:
Hi !!!
Greetings!!
I have the following php code

<?php
$db = mysql_connect("1", user, password)
or die ("canīt connect");
mysql_select_db(efemerides,$db);
mysql_close();
?>

I receive the error "canīt connect". Right beacuse "1" is not my
server.

Then I insert a function in the code and I do not receive the "canīt
connect" error. It seems that when I insert the function in the PHP
doesnīt work as it should

<?php
$db = mysql_connect("1", user, password)
"1" is not a valid host name. You should usually use "localhost"
or die ("no se ha podido conectar");
mysql_select_db(efemerides,$db);
function quitar($mensaje)
{
$mensaje = str_replace("<","<",$mensaje);
$mensaje = str_replace(">",">",$mensaje);
$mensaje = str_replace("\'","'",$mensaje);
$mensaje = str_replace('\"',""",$mensaje);
$mensaje = str_replace("\\\\","\",$mensaje);
return $mensaje;
}
mysql_close();
?>
Use PHP built-in escaping instead of making your own function:

$safe = htmlentities(get_magic_quotes_gpc() ? stripslashes($mensaje) :
$mensaje);
<snip>
--
Curtis, http://dyersweb.com
Feb 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nick | last post by:
Is there a way to reference the 'primary key' field of a record you are actually inserting at the moment. Im using an 'int auto increment' field as the primary key. I could reference it with a...
2
by: Marcus Smaby | last post by:
With the rich IDE on VB.net 2003, I was wondering if there is an easy way to set the event handler function for a hand-coded object (SqlConnection for example). I know that if I dim it withevents I...
2
by: Dennis | last post by:
This may be easy for most but I can't get this thing to work. I believe I followed all the instructions but when I click on the link no window opens just the default IE page cannot display. Here is...
3
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection...
4
by: frank | last post by:
I posted a question before (to too many groups) and this time I am sending to this group only. I have a quick script as seen below, the file_list table has a unique field called file_name. The...
3
by: geoffblanduk_nospam | last post by:
Given a set of intervals {i1, i2, i3, ...} a list is produced; the base items (0) are placed one at a time into the stream and after the ix one a interval item (1, 2, 3, etc) of the correct type is...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
12
by: Light | last post by:
Hi all, I posted this question in the sqlserver.newusers group but I am not getting any response there so I am going to try it on the fine folks here:). I inherited some legacy ASP codes in my...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.