-1

I am currently trying to setup a game.

I have tried a lot of things but nothing seems to have worked so far

$sql = "
select username
     , safe_username 
  from users 
 where id = $userid; 
UPDATE users 
   SET username = '$newusername' 
 where id = $userid
";

Error: select username, safe_username from users where id = 10; UPDATE users SET username = 'Deaga' where id = 10

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 username = 'Deaga' where id = 10' at line 1

I expected it to work. i am trying to setup a game. if you could help me thank you very much i am new to coding and i don't really know what to look for when i get these kind of errors.

7
  • You're missing a closing " at the end of the $sql assignment. (There may well be other things wrong, but that's what's causing the immediate error.) Commented Jun 12, 2019 at 21:20
  • Error: select username, safe_username from users where id = 10; UPDATE users SET username = 'dea' where id = 10 values ('10','dea')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 username = 'dea' where id = 10 values ('10','dea')' at line 1 Commented Jun 12, 2019 at 21:23
  • Then that's a different problem. I'd suggest deleting this question as it was just a typo. Then do some research into the new error before asking a new question if you need to. Commented Jun 12, 2019 at 21:28
  • 4
    you have TWO queries in one statement, that's the problem Commented Jun 12, 2019 at 21:39
  • Possible duplicate of Using PHP to execute multiple MYSQL Queries Commented Jun 12, 2019 at 23:00

1 Answer 1

1

Only one query at a time is allowed. You'll need to run each query separately in your php program.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.