receive an warning of mysql_real_escape_string

Discussion in 'PHP' started by mark103, Oct 2, 2010.

  1. #1
    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
    
    Code (markup):
    The error are jumping on this line:
    
        return mysql_real_escape_string($value); 
    
    Code (markup):

    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);
    ?>
    
    PHP:
    I have input the correct password, so what's wrong??
     
    mark103, Oct 2, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    You need a valid mysql connection open before usage of any mysql_* functions.
     
    danx10, Oct 2, 2010 IP
  3. mark103

    mark103 Active Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    can you please post the mysql function that I should use to replace the code like on mine?
     
    mark103, Oct 2, 2010 IP
  4. stOK

    stOK Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
  5. mark103

    mark103 Active Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #5
    Thanks for the help. Problem solved! :)
     
    mark103, Oct 3, 2010 IP