-2

I currently have this:

<?php
   $length = count($data['mark']);
   $i=0;
   $s=1;
   for($i=0;$i<$length;$i++){
       $sql="UPDATE `groupdatabase1` .`questions` SET `mark`=".$data['mark'][$i].", `feedback`= '".$data['feedback'][$i]."' WHERE `question`= ".$s." ;";
       mysql_query($sql);
       echo $sql;
   }
?>

I have an unknown amount of queries to run from this, meaning multiple queries in succession. How do I go about running them all one after another?

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
user1248092
  • 361
  • 1
  • 6
  • 19
  • First fix up your sql injection vulnerabilities. After that, what you've got will run all those queries, one afte rthe other. But you have no error checking whatsoever, which'll make it impossible to figure out why 1 (or more) of your zillions of queries failed. – Marc B Mar 27 '12 at 18:43
  • 1
    Your code is doing that right now, in the loop. Can you be more specific? – jeremyharris Mar 27 '12 at 18:43
  • Googleisyourfriend : http://stackoverflow.com/questions/8198707/running-multiple-php-scripts-at-the-same-time-database-loop-issue (one of the first link) if you want to launch at the same time. If it is not that I don't understand the question. – Jeremy D Mar 27 '12 at 18:46
  • You *are* running multiple SQL queries one after another. What's the issue here? – gen_Eric Mar 27 '12 at 18:46
  • Marc B do you mean by putting escape strings? And the code can run one query but I need a way of essentially conjoining multiple queries – user1248092 Mar 27 '12 at 18:47
  • I believe he wants to know how to run the updates concurrently rather than serially. – Rafe Mar 27 '12 at 18:49
  • @Rafe: In his title he says "at once", but in the question he says "one after another". – gen_Eric Mar 27 '12 at 18:50
  • 1
    @user1248092: you can't run multiple separate queries in a single mysql_query() call. The mysql driver for PHP does not allow it as a simple sql injection attack prevention method. – Marc B Mar 27 '12 at 18:52

2 Answers2

1

Use PDO, Prepared Statements and Transactions.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
  • 3
    How does that answer the question? – Umbrella Mar 27 '12 at 18:46
  • How does it not? I've listed everything needs to be done to solve the problem, one by one, and included pages to the relevant documentation. If he can't RTFM, this question isn't really worth solving (because he wouldn't have learned anything from it). – Madara's Ghost Mar 27 '12 at 18:47
0

mysql_query only allows one query per call, even if you use ';' so you will have to do several mysql_query calls, one for each query you want to run.

gosukiwi
  • 1,569
  • 1
  • 27
  • 44