Welcome_234
Welcome_234

Reputation: 43

How can I fix this syntax error on my PHP MySQL query

I have been trying to make a query in MYSQL, I am doing 2 things in 1 query. My host has a Limit to queries so I need to limit the amount of queries I am doing. When I did the query I get

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 ', (UPDATE users SET last_online=NOW() WHERE username='Welcome_234')' at line 1

I have put a semicolon ";" but it still doesn't work (This query worked in phpMyAdmin).

The code for the query is:

SELECT * FROM `users` WHERE username='Welcome_234',
UPDATE `users` SET last_online=NOW() WHERE username='Welcome_234'

I have tried many hours to figure out the problem and I still haven't found it.

Upvotes: 1

Views: 56

Answers (1)

Bill Karwin
Bill Karwin

Reputation: 562270

Most PHP interfaces to run MySQL queries don't support multiple queries per call. You must run them one query per call.

Your host's limit on queries can't be so low that the difference between one and two queries will break it. I would guess the limit is in place to prevent clients from running excessive loops that run thousands of queries. If it is so low that you can't run two queries, then get a different host.

Upvotes: 1

Related Questions