Mutley Posted December 13, 2006 Share Posted December 13, 2006 It lists the fields from the database so you can edit them but every time I try to update them, it updates the wrong one, the same one every time, id 5.Form file:[code]<?phprequire_once("connection.php");mysql_select_db("rufc");$result = mysql_query("SELECT id, image, caption, date, DATE_FORMAT(date,'%d-%m-%Y') AS dstamp FROM caption ORDER BY date DESC LIMIT 3");while($row = mysql_fetch_array( $result )) {?><form action="caption/update_confirm.php" method="POST"><input type="hidden" name="id" value="<?php echo $row['id']; ?>"><table width="90%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><center><img src="<?=$row['image'];?>" /></center></td> </tr> <tr> <td><center><?=$row['dstamp'];?></center></td> </tr> <tr> <td><center><input class="form" type="text" size="20" name="home" value="<?=$row['caption']; ?>"></center></td> </tr></table><input class="form" type="submit" value="Submit"> <?php }?></table>[/code]Update database file:[code]<?phpob_start();include("config.php");require_once("connection.php");$id = $_POST['id'];$image = $_POST['image'];$caption = $_POST['home'];$date = $_POST['date']; // what's the date?list($day, $month, $year) = explode("-", $date); // now split it up$update = date('Y-m-d', strtotime("$year/$month/$day")); // now re-form itmysql_select_db("rufc");$sql = "UPDATE caption SET caption='$caption' WHERE id = '".$id."' LIMIT 1";mysql_query($sql); echo "The selected information was updated!"; echo "<a href='caption.php'>Click here</a> to continue";?>[/code]Any idea? Link to comment https://forums.phpfreaks.com/topic/30498-whats-wrong-with-my-script/ Share on other sites More sharing options...
esukf Posted December 13, 2006 Share Posted December 13, 2006 Think you are missing the end </form> tag in the loop. Since all the hidden fields fields have the same name the last value is always passed to your action page. Link to comment https://forums.phpfreaks.com/topic/30498-whats-wrong-with-my-script/#findComment-140413 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.