Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5995055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:54:22+00:00 2026-05-22T23:54:22+00:00

I’m trying to use a MERGE INTO statement in my php file to update

  • 0

I’m trying to use a MERGE INTO statement in my php file to update or insert into a MySQL database for a multiplayer game.

Here’s a full description of what I’m trying to accomplish:

The php file is called with the following line from a javascript file:

xmlhttp.open('GET', "phpsqlajax_genxml.php?" + "lat=" + lla[0] + "&heading=" + truckHeading + "&lng=" + lla[1] + "&velocity0=" + vel0 + "&velocity1=" + vel1 + "&velocity2=" + vel2 + "&id=" + playerNumber, true);

This will be sending the php file information to update the database with. Either this will be a new player and the first time this information has been sent, meaning that a new row in the database will be created, or it will be a current player who just needs to have their information updated.

If it is a new player the “id” that is sent will be one that doesn’t yet exist in the database.

For some reason the database isn’t being updated, nor are new rows being added. I’m thinking it’s a syntax error because I don’t have much experience using MERGE statements. Could someone with experience with this please let me know what I might be doing wrong?

Here is the code before the MERGE INTO statement so you can understand which variables are which:

 $id = $_GET['id'];

 $lat = $_GET['lat'];

 $lng = $_GET['lng'];

 $heading = $_GET['heading'];

 $velocity0 = $_GET['velocity0'];

 $velocity1 = $_GET['velocity1'];

 $velocity2 = $_GET['velocity2'];

id is the column heading, $id is the id being passed in

Here is my current MERGE INTO statement in my php file:

  MERGE INTO markers USING id ON (id = $id)
  WHEN MATCHED THEN
  UPDATE SET lat = $lat, lng = $lng, heading = $heading, velocityX = $velocity0, velocityY = $velocity1, velocityZ = $velocity2
  WHEN NOT MATCHED THEN
  INSERT (id, name, address, lat, lng, type, heading, velocityX, velocityY, velocityZ)       VALUES ($id, 'bob', 'Poop Lane', $lat, $lng, 'Poop', $heading, $velocity0, $velocity1, $velocity2)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:54:23+00:00Added an answer on May 22, 2026 at 11:54 pm

    PHP’s database libraries invariably have their various function calls return FALSE if anything failed during the call. Assuming you’re on mysql_/mysqli_, then you shoudl be doing something like this:

    $sql = "MERGE INTO ....";
    $result = mysql_query($sql);
    if ($result === FALSE) {
        die(mysql_error());
    }
    

    It is poor practice to NOT check the return values from database calls. Even if the query string is 100% syntactically valid, there’s far too many ways for a query to fail. Assuming everything works is the easiest way to get yourself into a very bad situation. As well, when things do fail, the lack of error handling will simply hide the actual reason for the error and then you end up on SO getting answers like this.

    Oh, and before I forget… MySQL doesn’t support “MERGE INTO…”, so your whole query is a syntax error. Look into using “REPLACE INTO…” or “INSERT … ON DUPLICATE KEY UPDATE …” instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.