I have small form where you can edit the info in the data base but for some reason after i hit send on the edit form, the only info gets updated is the one in first now... help? 😕😕😕😕
Page displaying date, and containing link to Edit form:
<html>
<head>
<title>Edit</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("beyondmotors", $con);
$result = mysql_query("SELECT * FROM vehicles");
echo "<table border='2'>
<tr>
<th>ID</th>
<th>Year</th>
<th>Make</th>
<th>Model</th>
<th>Mileage</th>
<th>EDIT</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['year'] . "</td>";
echo "<td>" . $row['make'] . "</td>";
echo "<td>" . $row['model'] . "</td>";
echo "<td>" . $row['mileage'] . "</td>";
echo ("<td><a href=\"edit_form.php?id=$row[id]\">Edit</a></td></tr>");
echo "</tr>";
}
echo "</table>";
$result = mysql_query("SELECT * FROM vehicles");
echo "<table border='4'>
<tr>
<th>ID</th>
<th>Year</th>
<th>Make</th>
<th>Model</th>
<th>Mileage</th>
<th>EDIT</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['year'] . "</td>";
echo "<td>" . $row['make'] . "</td>";
echo "<td>" . $row['model'] . "</td>";
echo "<td>" . $row['mileage'] . "</td>";
echo ("<td><a href=\"delete.php?id=$row[id]\">Delete</a></td></tr>");
echo "</tr>";
}
echo "</table>";
mysql_close($con);
echo " <a href='main.php'>Return to main page</a>";
?>
</body>
</html>
Edit Form ( it echos the arrays correct so up until this point everything is okay):
<?php
$id=$_GET['id'];
mysql_connect("localhost","root","") or die("Error: ".mysql_error()); //add your DB username and password
mysql_select_db("beyondmotors");//add your dbname
//replace TestTable with the name of your table
$sql = "select * from vehicles where id='$id'";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)){
$id = $row['id'];
$year = $row['year'];
$make = $row['make'];
$model = $row['model'];
$mileage = $row['mileage'];
//we will echo these into the proper fields
}
mysql_free_result($query);
?>
<html>
<head>
<title>Edit User Info</title>
</head>
<body>
<form action="edit_data.php" method="post">
id:<br/>
<input type="text" value="<?php echo $id;?>" name="id" disabled/>
<br/>
Year:<br/>
<input type="text" value="<?php echo $year;?>" name="year"/>
<br/>
Make:<br/>
<input type="text" value="<?php echo $make;?>" name="make"/>
<br/>
Model:<br/>
<input type="text" value="<?php echo $model;?>" name="model"/>
</br>
Mileage:<br/>
<input type="text" value="<?php echo $mileage;?>" name="mileage"/>
</br>
<input type="submit" value="submit changes"/>
<?php echo " <a href='main.php'>Return to main page</a>";
?>
</form>
</body>
</html>
The update PHP script. once this goes through on first row in database is updated, all info gets updated correctly but it all goes in first now...I think something is wrong with the WHERE part but i cant first out what... UGH SO frustrating:
<?php
mysql_connect("localhost","root","") or die("Error: ".mysql_error()); //add your DB username and password
mysql_select_db("beyondmotors");//add your dbname
//get the variables we transmitted from the form
$id = @$_POST['id'];
$year = $_POST['year'];
$make = $_POST['make'];
$model = $_POST['model'];
$mileage = $_POST['mileage'];
//replace TestTable with the name of your table
$sql = "UPDATE vehicles SET year='$year', make='$make', mileage='$mileage', model='$model'
WHERE ID='id' LIMIT 1";
mysql_query($sql) or die ("Error: ".mysql_error());
echo "<a href='edit.php'>Return to edit info</a>";
echo "<a href='main.php'>Return to main page</a>";
?>