Jump to content

[SOLVED] PHP/MySql form submit


SocomNegotiator

Recommended Posts

Ok here is my while statement that each item from the DB displays in a form:

 

<?php 
while($row = $db->fetch_array())	{
	?>
		<form id='reorder_form' action='?page=reorder' method='post'><input type='hidden' name='order_number' value='<?=$row['order_number']?>'/>
		<li>
				<li>Item Name: <?=$row['name']?></li><br />
			<ul style="width: 200px; height: 125px;">
				<li>Quantity: <input type='text' name='amount' size='5' value='<?=$row['amount']?>' /><br /></li>
			</ul>
		</li>

	<?php
}
?>
</ul>
<br style="clear: left" />
</div>

	<center><input type='submit' name='submit' value='Re-Submit Order'/></center>
	</form>

</div>

 

Now you notice that the Quantity: is the only thing the user can change. Now how would I go about getting the quantity of the results from the while statement if there is more than one result and the form is submitted? For instance, I can do this on submit $amount = $_POST['amount'], but the post back for amount will be the first items quantity only. So how would I go about getting the second, third, fourth, etc quantities if there were more than one result that came back from the while loop?

Link to comment
https://forums.phpfreaks.com/topic/115794-solved-phpmysql-form-submit/
Share on other sites

Yeah id is the record on the table. Ok so when doing that..how do I do the $_POST? Is it just $amount = $_POST['amount'] or..?

 

 

Replace:

<input type='text' name='amount' size='5' value='<?=$row['amount']?>' />

with:

<input type='text' name='amount<?=$row['id']?>' size='5' value='<?=$row['amount']?>' />

Assuming that $row['id'] is the id of the record on the table.

Also how would I go about inserting the correct quantity with the correct item...here is my code for the after submitted

 

<?php
//BEGIN: Form Processing: Registration
if(isset($_POST['submit']))
{

$order_number = $_POST['order_number'];
$amount = $_POST['amount'];

$db->query("SELECT * FROM `order` ORDER BY order_number DESC LIMIT 1") or die(mysql_error());
$number = $db->fetch_array();
$num = 1;
if($num = $number['order_number'])
	$num = $number['order_number'] + 1;
elseif($number['order_number'] == "")
	$num = 1;
else
	$num = $num;

$res = mysql_query("SELECT * FROM `order` WHERE order_number = '$order_number'") or die(mysql_error());
while($r = mysql_fetch_array($res)){
$inserted=$db->query("INSERT INTO `order` (`order_number`,`pre_order_id` , `item_id` , `amount` , `user_id` )  VALUES (".$num.",".$r['pre_order_id'].", ".$r['item_id'].", ".$amount.", ".$r['user_id'].")") or die (mysql_error());

// track the id's of the new inserts
$insert_ids[] = mysql_insert_id();
}
if($error){
echo $error;
// remove any rows that HAVE been inserted from the pre_order table
$ids = implode("', '", $insert_ids);
  if($inserted){
  echo "Your order has been re-submitted.";
  } else {
  echo "Could not re-submit your order Error: ".mysql_error();
  }
} else {
  if($inserted){
  echo "Your order has been re-submitted.";
  } else {
  echo "Could not re-submit your order Error: ".mysql_error();
  }
}

}?>

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.