Monday, 3 September 2018

The mysql update does not work through the php script, although it runs through the mysql terminal

 I have a mysql table with a column named approved. In case i use the mysql script update tablename set columnname=1 where id=x where x is an integer number,everything works. The problem is when i try to use this script via PHP,where i have the following script:

$id = mysql_escape_string($_GET["id"]);

if(true){
    $update = 'update tablename set approved=1 where id='.$id;
    mysql_query($update);
    echo $update;
    echo '<br />database updated :)';
} else {
    echo 'An error occured';
}
//mysql_close($con);

where the update does not work..
it does not seem to me that somewhere i have something wrong,so why this does not work?? Do you have any ideas??
thank you in advance

Instead of
mysql_query($update);

try this:
$result = mysql_query($update);
if (!$result) {
    die('Invalid query: ' . mysql_error());
}

-- you'll see what's wrong with your query.

0 comments:

Post a Comment