Re: [PHP] problem with mysql_real_escape_string()



afan@xxxxxxxx wrote:
I moved my website from one php4/mysql4 based server to new hosting
company and php5/mysq5 based server.
Everything worked fine on old server, though now, on one page after I
submit new record, I'll get this error:

Warning: mysql_real_escape_string() [function.mysql-real-escape-string
<https://www.mydomain.com/function.mysql-real-escape-string>
]: Access denied for user 'daemon'@'localhost' (using password: NO) in
/srv/www/mydomain/add_record.php on line 30

Warning: mysql_real_escape_string() [function.mysql-real-escape-string
<https://www.mydomain.com/function.mysql-real-escape-string>
]: A link to the server could not be established in
/srv/www/mydomain.com/add_record.php on line 30

and this is a code:

26 if(isset($_POST['SubmitNewRecord']))
27 {
28 foreach($_POST as $key => $value)
29 {
30 ${$key} = mysql_real_escape_string($value);
31 }
32 }

Never got such a error message before.

Check the archives - this was asked a few days ago. The mysql_real_escape_string function requires a connection to the database to be open. If one isn't open it will try to open one with the defaults. All you need to do is make sure you connect to the mysql database before using mysql_real_escape_string.

-Stut
.



Relevant Pages

  • Re: PHP under CGI Directory
    ... >trying open a connection to a MySQL database using mysql_connect. ... >MySQL module when they compiled PHP. ... They told me their server is ...
    (comp.lang.php)
  • Re: Linux KSH93 Connecting to a networked MySQL database.
    ... MySQL database is on another server. ... Is there a way to accomplish a network connection to a MySQL database ...
    (comp.os.linux.misc)
  • ODBC link to MySQL, can write, but not edit or delete
    ... I have a MySQL database on a server in our shop, ... I have two queries, one which loads the table, ... But the delete query fails, as does VBA code with error 3027 ...
    (microsoft.public.access.externaldata)
  • Re: LOAD DATA INFILE issue
    ... need to import them into my mysql database. ... change the connection to my server, it seems tat the connection cant ... Maybe your server only allows MySQL connections from localhost. ...
    (comp.lang.php)
  • Re: PHP uses parameters names instead of values
    ... the function that connects to our MySQL database accepts ... the username, the password, the server name and the ... We're comparing the two ... So either your defines go wrong, or a possible the include of a file holding those defines goes wrong or is not being done entirely. ...
    (comp.lang.php)