tags:

views:

39

answers:

1
function updateDemo($demoTitle, $desc, $keyword, 
       $uploadedFile, $clientname, $uploadedImage, $adminName, $demoID)     
{   
    $query = "UPDATE demos SET dmTitle ='sdsdsdsdsd' , dmDesc = '$desc' , 
      dmKey = '$keyword' , dmLink= '$uploadedFile' , client='$clientname' , 
        imageTitle = '$uploadedImage' , userName = '$adminName' 
         WHERE id = '$demoID'";

    $result = mysql_query($query);
    if($result) {
        return 'yes';
    } else {
        return mysql_error();
       }
}

This is an update of the previous, question. I have the query executed and i am getting the return value as Yes, but it seems strange for me that the values are not getting updated.

Though when i check down here in PHP, i am getting the update values...

I tried to hardcode a value for title and it also seems not getting updated.

+4  A: 

Try to check what mysql_affected_rows() returns. If it's not 1, then your $demoID is probably wrong. If it is 1, you're probably looking in the wrong place in the DB.

And please, for security's sake, consider switching to a DB interface which supports prepared statements (mysqli, PDO) if possible.

Edit

Here's your code using PDO

function updateDemo($demoTitle, $desc, $keyword, 
       $uploadedFile, $clientname, $uploadedImage, $adminName, $demoID)     
{   

    $query = "UPDATE demos SET dmTitle = ? , dmDesc = ? , 
      dmKey = ? , dmLink= ?, client=? , 
        imageTitle = ? , userName = ?
         WHERE id = ?";

    global $db;
    $stmt = $db->prepare($query);
    $stmt->execute(Array(
        $demoTitle, $desc, 
        $keyword, $uploadedFile, $clientname,
        $uploadedImage, $adminName,
        $demoId
    ));

    return $stmt->rowCount();    
}

This assumes that you have a global variable $db holding a PDO connection (there are better solutions but it's the simplest and will probably suffice).

oggy
can you modify my code and fit in the mysql_affected_rows and a PDO, i shall learn something new