Results 1 to 4 of 4

Thread: Problem with MYSQL command ?

  1. #1

    Join Date
    Sep 2002
    Location
    Auckland
    Posts
    1,356
    Rep Power
    17

    Problem with MYSQL command ?

    Hi.

    Ive got a prob with the below MYSQL syntax.

    The error message is: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `Reference`='2015-09-a'' at line 4

    However ive googled a lot & trying to follow examples, but im not sure what can be wrong. I suspect its the typ of quote (double / single / back-tick etc..) but ive tried various types & no impovement.


    INSERT INTO `Master` ( `Reference` , `Title` , `description` )
    VALUES (

    "2015-09-a", "NASA Spacecraft takes GPS to New Heights", "As any backcountry hiker knows# Global Positioning System# or GPS# trackers are crucial for navigation. But they can also be a little finicky. Units sometimes lose lock when you walk into the shadow of a canyon wall# when you point the units at the ground# or even when you make a sharp turn. Now imagine a GPS system flying through the vacuum of space at 22#000 mph# rapidly spinning 43#000 miles above the surface of the blue planet below. Would it work?"
    ) ON DUPLICATE
    KEY UPDATE Title = "NASA Spacecraft takes GPS to New Heights",
    description = "As any backcountry hiker knows# Global Positioning System# or GPS# trackers are crucial for navigation. But they can also be a little finicky. Units sometimes lose lock when you walk into the shadow of a canyon wall# when you point the units at the ground# or even when you make a sharp turn. Now imagine a GPS system flying through the vacuum of space at 22#000 mph# rapidly spinning 43#000 miles above the surface of the blue planet below. Would it work?" WHERE `Reference` = '2015-09-a'

  2. #2

    Join Date
    Sep 2002
    Location
    Auckland
    Posts
    1,356
    Rep Power
    17
    Does anyone know the answer ?

    ive gone through a dozen combinations of backticks / single quotes, No quotes, double quotes - add salshes / strip slashes etc....

  3. #3

    Join Date
    Sep 2002
    Location
    Auckland
    Posts
    1,356
    Rep Power
    17
    The latest version I have is below. It is the MYSQL command (using MYSQLI). as ive drastically reduced the amount of text im using - Just for testing... & still get errors...

    any ideas ?

    INSERT INTO `Master` (`Reference`, `Title`, `description`)
    VALUES("2015-09-b", "Total Eclipse of the Harvest Moon", "This is a test description.")
    ON DUPLICATE KEY UPDATE
    (`Title`="Total Eclipse of the Harvest Moon", `description`="This is a test description.")
    WHERE
    Reference='2015-09-b'

    <br>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(`Title`="Total Eclipse of the Harvest Moon", `description`="This is a test desc' at line 4
    EDIT: Ive tried using where & without where clause.

  4. #4

    Join Date
    Sep 2002
    Location
    Auckland
    Posts
    1,356
    Rep Power
    17
    Hi.

    I thinkive fixed it - Though have a different problem (i'll put into a different thread)..

    my code is here. (it SAYS it is updated - & produces no errors).

    Ive had to separate it out into different SQLs



    $count=0;

    if ($result = $mysqli->query("SELECT Reference FROM Master where Reference='$_reference'")) {
    /* determine number of rows result set */
    $row_cnt = $result->num_rows;
    printf("Result set has %d rows.\n", $row_cnt);
    $result->close();
    }

    if($row_cnt>0)
    {
    $sql="UPDATE Master SET Title=\"$_title\", description=\"$_description\"
    WHERE
    Reference='$_reference'";
    }
    else
    {
    $sql="INSERT INTO `Master` ('Reference', 'Title', 'description')
    VALUES(\"$_reference\", \"$_title\", \"$_description\")";
    }

    if ($mysqli->query($sql) === TRUE) {
    echo "New record created successfully";
    } else {
    echo "Error: " . $sql . "<br>" . $mysqli->error;
    }
    $mysqli->close();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •