cupaball Posted February 14, 2009 Share Posted February 14, 2009 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 More sharing options...
PFMaBiSmAd Posted February 14, 2009 Share Posted February 14, 2009 If you are using mysqli, why aren't you using the mysqli_real_escape_string() function? Link to comment https://forums.phpfreaks.com/topic/145202-mysql_real_escape_string/#findComment-762149 Share on other sites More sharing options...
bubbasheeko Posted February 14, 2009 Share Posted February 14, 2009 Try: $name = mysqli_real_escape_string($_POST['name']); Link to comment https://forums.phpfreaks.com/topic/145202-mysql_real_escape_string/#findComment-762150 Share on other sites More sharing options...
PFMaBiSmAd Posted February 14, 2009 Share Posted February 14, 2009 The correct syntax, from the php manual - string mysqli_real_escape_string ( mysqli $link , string $escapestr ) Link to comment https://forums.phpfreaks.com/topic/145202-mysql_real_escape_string/#findComment-762152 Share on other sites More sharing options...
bubbasheeko Posted February 14, 2009 Share Posted February 14, 2009 Whoops...forgot about that...thanks PF! Link to comment https://forums.phpfreaks.com/topic/145202-mysql_real_escape_string/#findComment-762156 Share on other sites More sharing options...
cupaball Posted February 14, 2009 Author Share Posted February 14, 2009 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 https://forums.phpfreaks.com/topic/145202-mysql_real_escape_string/#findComment-762165 Share on other sites More sharing options...
Mchl Posted February 14, 2009 Share Posted February 14, 2009 $link is a database connection you made with mysqli_connect $escapestr is string to be escaped. Link to comment https://forums.phpfreaks.com/topic/145202-mysql_real_escape_string/#findComment-762168 Share on other sites More sharing options...
bubbasheeko Posted February 14, 2009 Share Posted February 14, 2009 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 https://forums.phpfreaks.com/topic/145202-mysql_real_escape_string/#findComment-762170 Share on other sites More sharing options...
Mchl Posted February 14, 2009 Share Posted February 14, 2009 bubbasheeko: Please don't confuse mysql extension with mysqli extensions. Their syntax is similar but it is NOT the same. You're introducing unnecessary confusion. Link to comment https://forums.phpfreaks.com/topic/145202-mysql_real_escape_string/#findComment-762188 Share on other sites More sharing options...
cupaball Posted February 14, 2009 Author Share Posted February 14, 2009 Thanks, I got it work! Link to comment https://forums.phpfreaks.com/topic/145202-mysql_real_escape_string/#findComment-762213 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.