By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,353 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,353 IT Pros & Developers. It's quick & easy.

Problem inserting a function - Easy question

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.