Jump to content

[SOLVED] Problem with loop and sql update


jaxdevil

Recommended Posts

Below is the code I am trying. Have not used loops very much so someone else will be able to easily figure this out. I have a form that posts the data to this page. The from fields are in the first code box below and the second is the update query where I am trying to use the loops. It is not right, breaks the code each time so I am not formatting something right:

 

?>
<input type="hidden" name="start" value="<?=$start?>">
<input type="hidden" name="end" value="<?=$end?>">
<input type="hidden" name="id[]" value="<?=$id?>">
<input type="hidden" name="scan_code[]" value="<?=$scan_code?>">

 

<?
require($_SERVER['DOCUMENT_ROOT'].'/includes/configs/sql_connect.php');
for ($x = $start; $x >= $end; $x++) {
      $query="UPDATE inventory SET `scan_code` = '$scan_code[]' WHERE id='$id[]'";
           $result =mysql_query($query) or die ("Problem with the query $query<br>: " . mysql_error());
} // end for
?>

Link to comment
https://forums.phpfreaks.com/topic/127861-solved-problem-with-loop-and-sql-update/
Share on other sites

Thanks.

 

I think I found something that would make sense, a foreach loop, but how can I define it with 2 post infos? I.e I have $id AND $scan_code and this would only work for looping base don ID:

 

 foreach($id as $ids) {  
echo "$ids <br />";  
}  

 

So how could I use that for both $id AND $scan_code ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.