nulled
nulled

Reputation: 413

MySQL "UPDATE" not working?

So I have the following code, I have made sure that both the variables have something stored in them, by echoing the results in both $lat and $long

    $lat = $latitude;
    $updatelat = mysql_query("UPDATE listings SET lat='". $lat ."' WHERE id='". $id ."'");
    $long = $longitude;
    $updatelong = mysql_query("UPDATE listings SET long='". $long ."' WHERE id='". $id ."'");

The $updatelat query works absolutely perfect, and the value is set in the database.

The $updatelong query however doesn't work, but there is definitely a value stored in $long

Can anyone see something obviously wrong with this code? There is definitely a column called long in my database. I am completely confused.

Upvotes: 0

Views: 598

Answers (3)

nulled
nulled

Reputation: 413

Simple fix for this

If queries such as this don't work:

$updatelat = mysql_query("UPDATE listings SET lat='". $lat ."' WHERE id='". $id ."'");

There is probably a clash with MySQL reserved keywords, so try using backticks

$updatelat = mysql_query("UPDATE listings SET `lat`='". $lat ."' WHERE `id`='". $id ."'");

and it works!

Upvotes: 0

P. Jairaj
P. Jairaj

Reputation: 1033

Why 2 queries? You can do it in one as the id is same.

$lat = $latitude;
$long = $longitude;
$updatelatlong = mysqli_query($connection, "UPDATE listings SET lat='". $lat ."',long='". $long ."' WHERE id='". $id ."'");

Upvotes: 1

Jorel Amthor
Jorel Amthor

Reputation: 1294

Do you do this $result = mysqli_query($con,$updatelong); ? It'd be helpfull to see more of your code than this little part

Upvotes: 0

Related Questions