Skip to content
Advertisement

SELECT id FROM table_name WHERE column = $variable

I’m trying to retrieve the id number of a record to use as a variable elsewhere. I only want the id from a record that has a particular value in another column. here is my code:

JavaScript

When I test I get: SQL syntax; check the manual that corresponds to your MySQL server versi0on for the right syntax to use near ‘order WHERE orderNumber = ‘5b0ea3’

Any ideas?

Advertisement

Answer

JavaScript

ORDER is a reserver word in SQL; I’d recommend you change the name of the table to something else.

If you really can’t, then you can escape column and table names with backticks:

JavaScript

Or

JavaScript

And also see the comments about stopping using mysqli_ functions – they’re insecure, and being deprecated.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement