Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple inputs - how to collect dor MySQL

Status
Not open for further replies.

salewit

Programmer
Oct 31, 2002
58
US
I've got a database that I want admin people to be able to update. Here's a look roughly at how the database would look to the admin person. Note all fields are editable by user:

Code:
Train Number | Description | Leaves
17           | Earlybird   | 9:10
23           | Rock Island | 12:02
422          | Soo Line    | 15:30
etc. etc. Here's the HTML I've got (simplified):
Code:
for loop {
echo "Train Number Description Leaves<br>";
echo "<input type='text' name='train$row[trnnum]' value='$row[trnnum]'>";
echo "<input type='text' name='descr$row[trnnum]' value='$row[descr]'>";
echo "<input type='text' name='leaves$row[trnnum]' value='$row[leaves]'>";
}

This kind of translates to name='train17', 'descr17', 'train23' etc.

How will I know what my input names will be? I'll have maybe 30 records with random names with large gaps inbetween (i.e. name='train7', name='train23' name = 'train422', etc).

Any advice?
 
you could make a drop down menu.. this should work

Hope this helped.

Grtz, Bertjh
 
call your input boxes like this
Code:
echo "<input type='text' name='train[$row[trnnum]]' value='".$row['trnnum']."'>";
echo "<input type='text' name='descr[$row[trnnum]]' value='".$row['descr']."'>";
echo "<input type='text' name='leaves[$row[trnnum]]' value='".$row['leaves']."'>";

then you can address them like so

Code:
for each ($_POST['train'] as $trainNumber){
  $description = $_POST['descr'][$trainNumber];
  $leaves = $_POST['descr'][$trainNumber];
  //write to a db
 mysql_query("update trains set description = '".mysql_escape_string($description)."', leaves =  '".mysql_escape_string($leaves)." where trainnumber = $trainNumber") or die ("can't query");
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top