-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.

Strawberry
  • 33,750
  • 13
  • 40
  • 57
Deagan
  • 1
  • 1
  • 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.) – Jon Skeet Jun 12 '19 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 – Deagan Jun 12 '19 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. – Jon Skeet Jun 12 '19 at 21:28
  • 4
    you have TWO queries in one statement, that's the problem –  Jun 12 '19 at 21:39
  • Possible duplicate of [Using PHP to execute multiple MYSQL Queries](https://stackoverflow.com/questions/50190903/using-php-to-execute-multiple-mysql-queries) – Dharman Jun 12 '19 at 23:00
  • @tim I don't know how to set that up yet :( – Deagan Jun 12 '19 at 23:12
  • run each separately. –  Jun 12 '19 at 23:14

1 Answers1

1

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

O. Jones
  • 103,626
  • 17
  • 118
  • 172