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
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.

Link to comment
Share on other sites

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]);

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.