Hi
I seem to be having trouble updating a record in the database. Any help will be much appreciated
Below is my code:
<?php
include ('connect.php');//Includes database connection details
error_reporting(0);
$_SESSION['username'] = "$username";
$Update = $_POST['update'];
$car_id= $_GET['car_id'];
$query = "SELECT manufacturer, make, year, price FROM cars WHERE car_id = '$car_id'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
$manufacturer = $row['manufacturer'];
$make = $row['make'];
$year = $row['year'];
$price = $row['price'];
}
?>
Here is my form
<form Method="POST" ACTION="edit.php">
<input type="hidden" name="car_id" value="<?php echo "$car_id"; ?>">
<table border="2" align="center">
<tr>
<td>Manufacturer</td><td><input name="manufacturer" type="text" value="<?php echo "$manufacturer";?>"></input></td>
</tr>
<tr>
<td>Make</td><td><input name="make" type="text" value="<?php echo "$make";?>"></input></td>
</tr>
<tr>
<td>Year:</td><td><input name="year" type="text" value="<?php echo "$year";?>"></input></td>
</tr>
<tr>
<td>Price</td><td><input name="price" type="text" value="<?php echo "$price";?>"></input></td>
</tr>
</table>
<p align="center">
<input type="submit" name="update" value="Update">
</input>
</p>
</form>
The above php works fine but I think theres a problem with the below, it just does not update the record in the database
<?php
if (isset($_POST['update'])) {
$manufacturer = $_POST["manufacturer"];
$make = $_POST["make"];
$year = $_POST["year"];
$price = $_POST["price"];
$sql = "UPDATE cars SET manufacturer = '$manufacturer', make = '$make', year = '$year', price = '$price'
WHERE car_id = $car_id";
$result = mysql_query($sql);
echo "<p align = 'center'>Thank you</p>";
}
?>