0

It has been quite a while since I have used SQL, so it all drained abit. But when I use this query, $selectionArray['id'] has the value of 1, it returns me with this error:

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 `id` = `1`' at line 1

This is the query:

$randomHashQuery = "INSERT INTO users (`hash`)
                    VALUES (`" . HASH . "`)
                    WHERE `id` = `" . intval($selectionArray['id']) ."`";

There is probably a really easy fix to this, but I can't seem to figure it out.

Oliver
  • 9,239
  • 9
  • 69
  • 100
top97
  • 39
  • 2
  • This is not a duplicate of the indicated question. – axiac May 22 '15 at 20:50
  • @axiac Yes it is. The problem is the OP has used backticks in spots where they should have used single/double quotes. Clearly, they need to read on the differences between them. – ceejayoz May 22 '15 at 20:51
  • @ceejayoz The cause of the error message is the `WHERE` clause, not the backticks. Sure, they will produce another error message after the `WHERE` clause is removed but they are not the cause of the error described in the question. – axiac May 22 '15 at 20:54
  • @axiac I've changed it into this now, resulting in the following error: http://pastebin.com/HyF9RkDW – top97 May 22 '15 at 20:56
  • 1
    @top97 There are two problems with this query: the [`INSERT`](http://dev.mysql.com/doc/refman/5.7/en/insert.html) statement does not allow a `WHERE` clause (because it doesn't make sense). If you want to modify an existing row then you have to use [`UPDATE`](http://dev.mysql.com/doc/refman/5.7/en/update.html). The second problem is the usage of the backticks. Read the answers of the linked question to find out where to use them. – axiac May 22 '15 at 21:00
  • @axiac Like I said, it drained a bit. And I totally forgot about UPDATE. I am dumb haha, thanks! – top97 May 22 '15 at 21:02

0 Answers0