Hi Could someone please take a look over this for me and let me know where I am going wrong please. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link href="cp_css/loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Edit Form</h1> <p><a href="http://localhost/dual_control_cars/control_panel">Control Panel</a></p> <ul> <?php //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost", "johnmev_user1", "Pass1"); //select which database you want to edit mysql_select_db("cp"); //If cmd has not been initialized if(!isset($cmd)) { //display all the cars $result = mysql_query("select * from data order by id"); //run the while loop that grabs all the cars while($r=mysql_fetch_array($result)) { //grab the model and the ID $make=$r["make"];//take out the model $model=$r["model"];//take out the model $id=$r["id"];//take out the id //show the make and model a link in a list echo "<li>"; echo "<a href='edit.php?cmd=edit&id=$id'>Edit - $make $model</a>"; echo "</li>"; } } ?> </ul> <?php if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") { if (!isset($_POST["submit"])) { $id = $_GET["id"]; $sql = "SELECT * FROM data WHERE id=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form action="edit.php" method="post"> <input type=hidden name="id" value="<?php echo $myrow["id"] ?>"> Make:<input type="text" name="make" value="<?php echo $myrow["make"] ?>" size=30 /><br /> Model:<input type="text" name="model" value="<?php echo $myrow["model"] ?>" size=30 /><br /> Spec:<input type="text" NAME="spec" value="<?php echo $myrow["spec"] ?>" size=30 /><br /> <input type="hidden" name="cmd" value="edit" /> <input type="submit" name="submit" value="submit" /> </form> <?php } ?> <?php if ($_POST["$submit"]) { $make = $_POST["make"]; $model = $_POST["model"]; $spec = $_POST["spec"]; $sql = "UPDATE data SET make='$make',model='$model',spec='$spec' WHERE id=$id"; $result = mysql_query($sql); echo "Thank you! Information updated."; } } ?> </body> </html> PHP:
Bonus points for why its only updating the last vehicle/id in the list of vehicles even when I go in to edit the first or second in the list.
$make = $_POST["make"]; $model = $_POST["model"]; $spec = $_POST["spec"]; $id = $_POST['id']; //<------ add this line $sql = "UPDATE data SET make='$make',model='$model',spec='$spec' WHERE id=$id"; PHP: