0

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.

16
  • add your create statement of the table Commented Jan 27, 2016 at 17:03
  • I don't have that to hand. The 'lat' and 'long' columns are both TEXT. Commented Jan 27, 2016 at 17:05
  • sienote: stop using deprecated mysql_* functions! and start using pdo or mysqli to have a higher security (better prevention to sqlinjections) Commented Jan 27, 2016 at 17:05
  • 2
    What's the value in $long? You might have an escaping issue. Commented Jan 27, 2016 at 17:08
  • 1
    You can avoid escaping/quoting/etc. issues by using prepared statements, although that would mean you'd have to stop using the mysql_* api (which you should do anyway because it's deprecated in PHP5 and gone from PHP7. ;) ) Commented Jan 27, 2016 at 17:17

3 Answers 3

1

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 ."'");
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.