Jump to content

receive an warning of mysql_real_escape_string


mark103

Recommended Posts

Hi guys,

 

I am having a problem of deleting the rows in the database. I just receive two warnings of mysql_real_escape_string which they are:

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'myusername'@'localhost' (using password: NO) in /home/username/public_html/mysite.com/delete.php on line 11

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in  /home/username/public_html/mysite.com/delete.php on line 11 failed

 

The error are jumping on this line:

    return mysql_real_escape_string($value); 

 

 

Here it the full code:

 

<?php
session_start();
    define('DB_HOST', 'localhost');
    define('DB_USER', 'username');
    define('DB_PASSWORD', 'password');
    define('DB_DATABASE', 'databasename');


function clean($value)
{ 
    return mysql_real_escape_string($value); 
} 

$id = clean($_GET['id']);

if ($id != NULL)
{
$query = @mysql_db_query(_DB,"DELETE FROM table1 WHERE $id = 'id");
$deleted = @mysql_affected_rows();

if($deleted > 0) {
    echo("worked");
    } else {
        echo("failed");
}
}else{
echo("failed");
}
@mysql_close($link);
?>

 

I have input the correct password, so what's wrong??

if you would remove all the @'s you put in your code to hide the php errors that are occurring on each one of those mysql_ instructions, you would probably learn that you are not making a connection to the database server.

 

Also, mysql_db_query() is depreciated and should be replaced with a call to mysql_select_db() and you should use mysql_query() to perform queries.

Thanks for your help, I have make some change:

 

<?php
session_start();
    define('DB_HOST', 'localhost');
    define('DB_USER', 'username');
    define('DB_PASSWORD', 'password');
    define('DB_DATABASE', 'databasename');

function clean($value)
{ 
    return mysql_real_escape_string($value); 
} 

$id = clean($_GET['id']);

if ($id != NULL)
{
$query = mysql_select_db("DELETE FROM table1 WHERE id = '$id'");
$deleted = @mysql_affected_rows();

if($deleted > 0) {
    echo("worked");
    } else {
  echo("failed");
}
}else{
echo("failed");
}
@mysql_close($link);
?>

 

 

However, I still getting the same errors. Any idea?

You have defined your database connection info, but have not actually connected to your database!

 

You still haven't connected to the database.

 

Ken

 

I know that I still haven't connected to the database. In which line I need to change it with?

Archived

This topic is now archived and is closed to further replies.

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