title: PHP Mysql Statement - multiple statements
body: <p>I have a PHP page that displays the results of a mysql query. each returned record is assigned a check box with the a value equal to the Row ID column.</p>
  
  <p>the mysql statement in place inserts the selected rows into a new table.</p>
  
  <p>I would like to add a second mysql query that updates the status of another table where the selected ID's match. the query is below:</p>
  
  <blockquote>
    <p>UPDATE despgoods_alldetails,loaddetails SET
    despgoods_alldetails.locstatus ='LoadCreated' WHERE
    despgoods_alldetails.despgoodsid = $val</p>
  </blockquote>
  
  <p>The page PHP Code that works currently is( I am aware of some incorrect code):</p>
  
  <pre><code>&gt; &lt;?php
  &gt;     mysql_connect("localhost", "hulamin_hulamin", "Hulamin2011")or die("cannot connect");    
  &gt;     mysql_select_db("hulamin_loc")or die("cannot select DB");
  &gt;     $sql="SELECT `despgoodsid`,`crtd dept`,`customer`,`loc cust rel`,`case no`,`gross mass`,`case width`,`case length` from
  &gt; despgoods_alldetails where transporttypename= 'localpmb' and
  &gt; locstatus='unplanned' and customer &lt;&gt; 'customer'";
  &gt;     $result=mysql_query($sql);
  &gt;     $count=mysql_num_rows($result);   putenv("TZ=Africa/Johannesburg");   ?&gt; &lt;table border=0&gt;
  &gt;     &lt;tr&gt;
  &gt;         &lt;td&gt;
  &gt;             &lt;form name="form1" method="post"&gt;
  &gt;                 &lt;table border=0
  &gt;                     &lt;tr&gt;
  &gt;                         &lt;th&gt;&amp;nbsp;&lt;/th&gt;
  &gt;                         &lt;th width=150&gt;Dispatch Area&lt;/th&gt;                      
  &gt;                         &lt;th width=150&gt;Customer&lt;/th&gt;  
  &gt;                       &lt;th width=150&gt;&lt;center&gt;Release Number&lt;/th&gt;
  &gt;                       &lt;th width=130&gt;&lt;center&gt;Case Number&lt;/th&gt;
  &gt;                       &lt;th width=80&gt;&lt;center&gt;Weight&lt;/th&gt; 
  &gt;                       &lt;th width=80&gt;&lt;center&gt;Width&lt;/th&gt; 
  &gt;                       &lt;th width=80&gt;&lt;center&gt;Length&lt;/th&gt; 
  &gt;                   &lt;/tr&gt; &lt;?php
  &gt;     while($rows=mysql_fetch_array($result)){ ?&gt;
  &gt;                     &lt;tr&gt;
  &gt;                         &lt;td&gt;&lt;input type="checkbox" name=check[]  value="&lt;?php echo $rows['despgoodsid']; ?&gt;"&gt;&lt;/td&gt;
  &gt;                         &lt;td&gt;&lt;?php echo $rows['crtd dept']; ?&gt;&lt;/td&gt;
  &gt;                         &lt;td&gt;&lt;?php echo $rows['customer']; ?&gt;&lt;/td&gt;
  &gt;                       &lt;td&gt;&lt;center&gt;&lt;?php echo $rows['loc cust rel']; ?&gt;&lt;/td&gt;
  &gt;                         &lt;td&gt;&lt;center&gt;&lt;?php echo $rows['case no']; ?&gt;&lt;/td&gt;
  &gt;                         &lt;td&gt;&lt;center&gt;&lt;?php echo $rows['gross mass']; ?&gt;&lt;/td&gt;
  &gt;                       &lt;td&gt;&lt;center&gt;&lt;?php echo $rows['case width']; ?&gt;&lt;/td&gt;
  &gt;                       &lt;td&gt;&lt;center&gt;&lt;?php echo $rows['case length']; ?&gt;&lt;/td&gt;
  &gt;                       
  &gt;                     &lt;/tr&gt;                                   
  &gt; 
  &gt; &lt;?php
  &gt;     } ?&gt;
  &gt;                     &lt;tr&gt;
  &gt;                         &lt;td colspan=3&gt;&lt;input name="Next" type="submit" id="Next" value="Next"&gt;&lt;/td&gt;
  &gt;                     &lt;/tr&gt;
  &gt;                     &lt;?php
  &gt;                     
  &gt;                     
  &gt;                             
  &gt;                             $check=$_POST['check'];
  &gt;                             
  &gt;                         if($_REQUEST['Next']=='Next'){  {
  &gt;                             $sql="INSERT INTO loaddetails (despgoodsid,dispatcharea,Customer, casenumber, weight, loadstatus) 
  &gt;                           SELECT `despgoodsid`,`crtd dept`,Customer,`case no`,`gross mass`,'loadplanned'
  &gt;                           FROM despgoods_alldetails WHERE `despgoodsid` = '$val'";
  &gt;                             
  &gt;                             foreach($check as $key=&gt;$value)
  &gt;                             {
  &gt;                             $sql="INSERT INTO loaddetails (despgoodsid,dispatcharea,Customer, casenumber, weight, loadstatus)
  &gt;                           SELECT `despgoodsid`,`crtd dept`,Customer,`case no`,`gross mass`,'loadplanned'
  &gt;                           FROM despgoods_alldetails WHERE `despgoodsid` = '$value'";
  &gt;                             $final=mysql_query($sql);
  &gt;                             if($final)
  &gt;                             {
  &gt;                             echo "&lt;meta http-equiv=\"refresh\" content=\"0;URL=http://www.hulaminloc.co.za/planningplatform/planlocalpmbstep2.php\"&gt;";
  &gt;                             }                                            } 
  &gt;                                 }
  &gt;                                 }
  &gt;                    mysql_close(); ?&gt; &lt;/table&gt; &lt;/form&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;
  </code></pre>
  
  <p>How can I add my update statement to run in addition to the select statement for each selected row?</p>
  
  <p>Any help is appreciated.</p>
  
  <p>Thanks and Regards,
  Ryan Smith</p>