Jump to content

mysql_real_escape_string()


cupaball

Recommended Posts

I have a form that is doing  basic insert to a db. My connection is a mysqli, but for some reason when I use the

$name =  mysql_real_escape_string($_POST[name]);

I get these errors:

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/l/o/o/looking4amb/html/beta/PHP/join_mailling.php on line 6

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/content/l/o/o/looking4amb/html/beta/PHP/join_mailling.php on line 6

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/l/o/o/looking4amb/html/beta/PHP/join_mailling.php on line 7

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/content/l/o/o/looking4amb/html/beta/PHP/join_mailling.php on line 7

 

If if just use $Post [name]; it works fine.

 

Can anyone help?

Link to comment
https://forums.phpfreaks.com/topic/145202-mysql_real_escape_string/
Share on other sites

The correct syntax, from the php manual -

 

string mysqli_real_escape_string ( mysqli $link , string $escapestr )

 

Thanks, that's the part I didn't understand. I read the php manu, but I am not sure how to write the syntax for the mysqli real escape what is the $link and what is the $escapestr. Would I put the $post in both places? 

 

Thanks for you help. You guys are way more help than the folks on the devnetwork forum.

To further the example by Mchl.

 

Your database connection:

$link = mysql_connect ( $hostname, $username, $password ) or trigger_error ( mysql_error(),E_USER_ERROR );
mysql_select_db ( $database );

 

Your mysqli string:

$name =  mysql_real_escape_string($link, $_POST[name]);

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.