Hi All Can someone please put me on right direction, I'm trying to Edit a field called $fare from the database, this code below works fine as long as there is only one field called $fare1. My problem is there are 21 fields like this one for each customer e.g $cust1, $fare1, $cust2, $fare2 ... How the devil do I Update them all. If I write multipul rows in the form then they all show. I hope I'm making some sense. Some help will be really appreciated if($_POST['amend']){ $id = $_POST["id"]; $fare1=$_POST["fare1"]; $query = "UPDATE restHotel SET fare1 = '$fare1' WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in Updating the query: $query. ".mysql_error()); } if($_POST['edit']) { foreach($_POST as $id) { $query = "SELECT * FROM restHotel WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result); ?> <form action="<?php echo $PHP_SELF ?>" method="POST"> <table width="100%" border="0"> <tr> <td>ID</td> <td><input type="text" name="id" value="<?php echo $row["id"]?>" size="3"/></td> </tr><tr> <td>Date/Time</td> <td><input type="text" name="dateTime" SIZE=25 value="<?php echo $row["dateTime"]; ?>" /> </td> </tr> <tr> <td>Pass type</td> <td><input type="text" name="passType" SIZE=30 value="<?php echo $row["passType"]; ?>"/> </td> </tr><tr> <td>Customer Name</td> <td><input type="text" name="custname1" SIZE=30 value="<?php echo $row["custname1"]; ?>"/> </td> </tr><tr> <td>Destination</td> <td><input type="text" name="des1" SIZE=30 value="<?php echo $row["des1"]; ?>"/> </td> </tr><tr> <td>Fare</td> <td><input type="text" name="fare1" SIZE=10 value="<?php echo $row["fare1"]; ?>"/> </td> </tr><tr><td> <input name="amend" type="Submit" value="Amend" onClick="return confirm('You are about to change this record, Are you sure you want to do this?');"/> </center></td> </table> </center> </form> <?php //Otherwise no rows found } //else echo "No rows found"; exit(); } PHP: Thanks Zed
I'm not sure if this is what you mean but simply ad commas and next field like $query = "UPDATE restHotel SET fare1 = '$fare1', fare2 = '$fare2', etc = 'etc' WHERE id = '$id'";