1

I'm trying to execute two SQL statements in one mysql_query.

$mySql = mysql_query("SELECT itemid, points FROM items WHERE id='1' UPDATE accounts SET userpoints = '1000'");

Is this possible? Thanks!

3 Answers3

3

You can only execute one query in mysql_query (even if you seperate the queries with the semicolon terminator).

You have to call them seperately (although this guy has a method to automate that).

Ross
  • 44,756
  • 37
  • 116
  • 169
2

If you use mysqli you can use mysqli_multi_query()

Tom Haigh
  • 56,170
  • 20
  • 110
  • 140
  • A better solution - if you're using PHP5 take advantage of MySQLi! – Ross Mar 10 '09 at 18:23
  • Be carefull with that though, MySQLi is **even more susceptible to SQL injections**, because it allows this kind of code: http://stackoverflow.com/questions/332365/xkcd-sql-injection-please-explain – Johan May 28 '11 at 21:32
0

I wouldn't try doing that since you won't be able to exploit the results from the different queries (returned values, mysql_insert_id(), ...)

Gad
  • 39,904
  • 13
  • 53
  • 78