Skip to main content
Participating Frequently
January 12, 2011
Question

mysql_real_escape_string() error

  • January 12, 2011
  • 2 replies
  • 1931 views

Hey guys,


Why do I get an error when I try to keep the incoming data harmless using mysql_real_escape_string() function?

$pavadinimas = $_POST['name'];
$tekstas = $_POST['tekstas'];
$id = $_POST['id'];
mysql_real_escape_string($pavadinimas);
mysql_real_escape_string($tekstas);
mysql_real_escape_string($id);

Cheers,

DissidentPJ

This topic has been closed for replies.

2 replies

David_Powers
Inspiring
January 13, 2011

DissidentPJ wrote:

Why do I get an error when I try to keep the incoming data harmless using mysql_real_escape_string() function?

You must connect to the database before you can use mysql_real_escape_string(). See http://docs.php.net/manual/en/function.mysql-real-escape-string.php.

January 12, 2011

What is the error you are getting?

Gary

Participating Frequently
January 12, 2011

PLENTY OF THEM:

Warning:  mysql_real_escape_string() [function.mysql-real-escape-string]: [2002] A connection attempt failed because the connected party did not  (trying to connect via tcp://localhost:3306) in D:\Darbai\serveris\UniServer\www\update.php on line 15

Warning:  mysql_real_escape_string() [function.mysql-real-escape-string]:  A connection attempt failed because the connected party did not  properly respond after a period of time, or established connection  failed because connected host has failed to respond.  in D:\Darbai\serveris\UniServer\www\update.php on line 15

Warning:  mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in D:\Darbai\serveris\UniServer\www\update.php on line 15

Warning:  mysql_real_escape_string() [function.mysql-real-escape-string]: [2002] A connection attempt failed because the connected party did not  (trying to connect via tcp://localhost:3306) in D:\Darbai\serveris\UniServer\www\update.php on line 16

Warning:  mysql_real_escape_string() [function.mysql-real-escape-string]:  A connection attempt failed because the connected party did not  properly respond after a period of time, or established connection  failed because connected host has failed to respond.  in D:\Darbai\serveris\UniServer\www\update.php on line 16

Warning:  mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in D:\Darbai\serveris\UniServer\www\update.php on line 16

Warning:  mysql_real_escape_string() [function.mysql-real-escape-string]: [2002] A connection attempt failed because the connected party did not  (trying to connect via tcp://localhost:3306) in D:\Darbai\serveris\UniServer\www\update.php on line 17

Warning:  mysql_real_escape_string() [function.mysql-real-escape-string]:  A connection attempt failed because the connected party did not  properly respond after a period of time, or established connection  failed because connected host has failed to respond.  in D:\Darbai\serveris\UniServer\www\update.php on line 17

Warning:  mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in D:\Darbai\serveris\UniServer\www\update.php on line 17

January 12, 2011

The errors are telling you that the connection was not made to your database. I assume you are trying to connect to your local testing server?  If you are trying to connect to your remote server, then your connection settings are wrong, they are pointing to your hard drive, Most likely a case of you changing from local to remote connections.

If that is not the case, and since you only have 3 instances, remove the mysql_real_escape_string() function and test your connection.  If you do connect, then you would need to post more information to see where you are going astray.

Gary