lynxus Posted August 12, 2009 Share Posted August 12, 2009 Hi all, Ive recently moved to a new server. Everything seems to work fine apart from code that uses the above. Does anyone have any idea how to fix this? [Wed Aug 12 09:31:32 2009] [error] [client 92.233.58.xxx] PHP Warning: mysql_real_escape_string() [<a href='function.mysql-real-escape-string'>function.mysql-real-escape-string</a>]: A link to the server could not be established in /var/ www/html/imsupporting/leavemessage.php on line 73, referer: http://support1.imsupporting.com/xxxxxxxxxx ( Line73: $email = mysql_real_escape_string($email); ) The database connection is setup fine ( if i dont use the escape string it works. ) Other php scripts run fine, i cant see any problems with the DB or connection to it. So i have no idea what this error is referring too. Any ideas? Thanks G Quote Link to comment https://forums.phpfreaks.com/topic/169892-solved-problems-with-mysql_escape_string/ Share on other sites More sharing options...
Adam Posted August 12, 2009 Share Posted August 12, 2009 Show us your code... Quote Link to comment https://forums.phpfreaks.com/topic/169892-solved-problems-with-mysql_escape_string/#findComment-896255 Share on other sites More sharing options...
lynxus Posted August 12, 2009 Author Share Posted August 12, 2009 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Welcome</title> <style type="text/css"> <!-- body,td,th { color:#FFFFFF; font-family: Arial, Helvetica, sans-serif; font-size: 14px; } .offlinemsgtxt { color: #333333; font-weight: bold; } body { background-color:#ffffff; margin-top: 0px; padding-top: 0px; background-image:url(Images/welcome_bg.png); background-repeat:no-repeat; } .style1 { color: #666666; font-weight: bold; } .style2 { color: #666666; font-size: 9px; } --> </style> </head> <body> <p> <script language=JavaScript> <!-- //Disable right click script III- By Renigade (renigade@mediaone.net) //For full source code, visit http://www.dynamicdrive.com var message=""; /////////////////////////////////// function clickIE() {if (document.all) {(message);return false;}} function clickNS(e) {if (document.layers||(document.getElementById&&!document.all)) { if (e.which==2||e.which==3) {(message);return false;}}} if (document.layers) {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} document.oncontextmenu=new Function("return false") // --> </script> <?php $siteid = $_POST['siteid']; $username = $_POST['name']; $phone = $_POST['phone']; $message = $_POST['message']; $email = $_POST['email']; $siteid = mysql_real_escape_string($siteid); $username = mysql_real_escape_string($username); $phone = mysql_real_escape_string($phone); $message = mysql_real_escape_string($message); $email = mysql_real_escape_string($email); // BEGIN ERROR CHECKING! if ($siteid == ""){ $siteid = "void"; } function strip_these($input){ $stuff_to_strip = array("\\","/","%","'","&",".",",","!"," "); return str_ireplace($stuff_to_strip,"",$input); } // Use above fucntion to check data. $siteid = strip_these($siteid); //change min and max length values accordingly $min = 1; $max = 20; //will only allow alphanumerical characters if(!eregi("^[a-zA-Z0-9]{".$min.",".$max."}$",$siteid)){ //do not allow $siteid = "void"; } // END ERROR CHECK $con = mysql_connect("localhost","USERNAME","PASSWORD"); // These are correct in the actual code. if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("imsupporting", $con); mysql_query("INSERT INTO offlinemessages (name, email, phone, message, time, siteid) VALUES ('$username', '$email', '$phone', '$message', NOW(), $siteid)"); $result = mysql_query("SELECT email FROM admins WHERE siteid = '$siteid' limit 1"); while($row = mysql_fetch_array($result)) { $adminmail = $row['email']; } mysql_close($con); // Send mail to admin of this site. function send_email($from, $to, $subject, $message){ $headers = "From: ".$from."\r\n"; $headers .= "Reply-To: ".$from."\r\n"; $headers .= "Return-Path: ".$from."\r\n"; $headers .= "Content-type: text/html\r\n"; if (mail($to,$subject,$message,$headers) ) { } else { } } $message = ""; $subject = "You have a new OFFLINE message"; $message .= "<html><body>"; $message .= "<b>You have a new offline message.<br></b>"; $message .= 'Please login to <a href="http://admin.imsupporting.com">http://admin.imsupporting.com </a> to read it.<br>'; $message .= "<br>Regards, <br>IMsupporting.com"; $message .= "</body></html>"; send_email("IMsupporting System <support@imsupporting.com>", $adminmail, $subject , $message); ?> <br /> </p> <p align="center"><span class="style1">Thank you <br /> <br /> Your message has been recorded <br /> <br /> <br /> </span><span class="style2">You may close this window</span> </p> Quote Link to comment https://forums.phpfreaks.com/topic/169892-solved-problems-with-mysql_escape_string/#findComment-896256 Share on other sites More sharing options...
dgoosens Posted August 12, 2009 Share Posted August 12, 2009 if this is your code: $email = mysql_real_escape_string($email) you forgot the link identifier http://be.php.net/manual/en/function.mysql-real-escape-string.php string mysql_real_escape_string ( string $unescaped_string [, resource $link_identifier ] ) Quote Link to comment https://forums.phpfreaks.com/topic/169892-solved-problems-with-mysql_escape_string/#findComment-896257 Share on other sites More sharing options...
lynxus Posted August 12, 2009 Author Share Posted August 12, 2009 if this is your code: $email = mysql_real_escape_string($email) you forgot the link identifier http://be.php.net/manual/en/function.mysql-real-escape-string.php string mysql_real_escape_string ( string $unescaped_string [, resource $link_identifier ] ) Er, what do you mean? This worked before so im not sure what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/169892-solved-problems-with-mysql_escape_string/#findComment-896258 Share on other sites More sharing options...
Adam Posted August 12, 2009 Share Posted August 12, 2009 No the link identifier is optional, however if one isn't specified it tries to use the last open connection. For some reason it may not be able to and throwing an error. Try moving your connection code before you use mysql_real_escape_string(). Quote Link to comment https://forums.phpfreaks.com/topic/169892-solved-problems-with-mysql_escape_string/#findComment-896259 Share on other sites More sharing options...
lynxus Posted August 12, 2009 Author Share Posted August 12, 2009 No the link identifier is optional, however if one isn't specified it tries to use the last open connection. For some reason it may not be able to and throwing an error. Try moving your connection code before you use mysql_real_escape_string(). Ah ha, That seems to of resolved it. I couldnt figure out where this "connecting" thing was coming from. Thanks muchly MrAdam. works great. Thanks G Quote Link to comment https://forums.phpfreaks.com/topic/169892-solved-problems-with-mysql_escape_string/#findComment-896261 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.