Jump to content

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 ?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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