I have a table in my database that look like this:
id - name - orderno

the table has data in the fields of id and name but orderno is empty.
I made a html form based on the data of this field, in front of each name field there is an text input field. when the user submits the data I want every value in the text input field to be inserted in the orderno of the relevant id.

is this possible?

7 Years
Discussion Span
Last Post by nav33n

Yeah, possible. Have a hidden field in the form to store the id. When the user clicks submit, update the table :)

update table set orderno='".$_POST['orderno']."' where id='".$_POST['id']."'";

thanks for the reply, that is what I did.
However, I was wondering how would I do it for more than one field. I tired to name the text input "orderno[]" and then use foreach loop to extract the values, but I could not assign each of the values to its related id.


Okay.. This is a sloppy example, just to give you an idea.

if(isset($_POST['submit'])) {
	print "<pre>";
	print "Id array => <br />";
	print "Order no array => <br />";
	print "</pre>";
       for($i=0;$i< count($_POST['orderno']); $i++) { //there will be equal number of elements in both id array and orderno array. 
		echo $_POST['id'][$i]." -> ".$_POST['orderno'][$i]."<br />";
<form method="post">
for($i=0;$i<5;$i++) {
<input type='hidden' name='id[]' value='<?php echo $i; ?>'> 
Order <?php echo $i; ?>:<input type="text" name="orderno[]"><br />
<input type="submit" name="submit" value="submit">

Instead of for loop, you will have while($row = mysql_fetch_array($result)) . Instead of assigning $i as value to the hidden field, you will have the counter/id field of the table.
You can then map the values of the array entered by the user in the orderno field to id field.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.