Update Problem
Posted: Mon May 16, 2011 12:49 pm
Hey
I have a slight problem!
I have a form which is connected to a mysql database!
With this form, I wish to edit the content of the mysql database!
Each element in this form is pre-filled! [so this shows the connect file is working]
This is the code for my Edit page
Please help me out!
Thanx
I have a slight problem!
I have a form which is connected to a mysql database!
With this form, I wish to edit the content of the mysql database!
Each element in this form is pre-filled! [so this shows the connect file is working]
This is the code for my Edit page
<html> <?php include('connect.php'); $id = $_GET['id']; $query = mysql_query("SELECT * FROM stocklist WHERE ID = '$id'"); $data = mysql_fetch_assoc($query); ?> <head><title>Manage a Previous Vehicle - Admin Area - High Spec Prestige</title></head> <body> <form action="doEdit.php" method="post"> <table> <tr> <td> <label for="titleL">Title</label> </td> <td> <input type="text" name="title" value="<?php echo $data['Title']; ?>"/> </td> </tr> <tr> <td> <label for="RegistrationL">Vehicle Registration</label> </td> <td> <input type="text" name="Registration" value="<?php echo $data['Registration']; ?>"/> </td> </tr> <tr> <td> <label for="YearL">Year/Reg</label> </td> <td> <input type="text" name="Year" value="<?php echo $data['Year']; ?>"/> </td> </tr> <tr> <td> <label for="BodyL">Body Type</label> </td> <td> <input type="text" name="Body" value="<?php echo $data['Body']; ?>"/> </td> </tr> <tr> <td> <label for="TransmissionL">Transmission</label> </td> <td> <input type="text" name="Transmission" value="<?php echo $data['Transmission']; ?>"/> </td> </tr> <tr> <td> <label for="FuelL">Fuel</label> </td> <td> <input type="text" name="Fuel" value="<?php echo $data['Fuel']; ?>"/> </td> </tr> <tr> <td> <label for="ColourL">Colour</label> </td> <td> <input type="text" name="Colour" value="<?php echo $data['Colour']; ?>"/> </td> </tr> <tr> <td> <label for="EngineL">Engine Size</label> </td> <td> <input type="text" name="Engine" value="<?php echo $data['Engine']; ?>"/> </td> </tr> <tr> <td> <label for="MileageL">Mileage</label> </td> <td> <input type="text" name="Mileage" value="<?php echo $data['Mileage']; ?>"/> </td> </tr> <tr> <td> <label for="DescriptionL">Description</label> </td> <td><textarea name="Description" cols="30" rows="7"><?php echo $data['Description']; ?></textarea> </td> </tr> <tr> <td> <label for="priceL">Price</label> </td> <td> <p> <input type="text" name="price" value="<?php echo $data['Price']; ?>"/> </p></td> </tr> </table> <table> <tr> <td width="166.5"> <label><input type="radio" name="Availability" value="1" checked>Available</label> </td> <td width="166.5"> <label><input type="radio" name="Availability" value="0">Sold</label></td> </tr> <tr><td><input type="submit" name="submit" /></td></tr> <tr><td><input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" /></td></tr> </table> </form> </body> </html>And this is the code for the forms action page i.e. doedit.php
<?php include('connect.php'); if(isset($_POST['submit'])) { if(isset($_POST['Title'])) { $Title = $_POST['Title']; if(isset($_POST['Registration'])) { $Registration = $_POST['Registration']; if(isset($_POST['Year'])) { $Year = $_POST['Year']; if(isset($_POST['Body'])) { $Body = $_POST['Body']; if(isset($_POST['Transmission'])) { $Transmission = $_POST['Transmission']; if(isset($_POST['Fuel'])) { $Fuel = $_POST['Fuel']; if(isset($_POST['Colour'])) { $Colour = $_POST['Colour']; if(isset($_POST['Engine'])) { $Engine = $_POST['Engine']; if(isset($_POST['Mileage'])) { $Mileage = $_POST['Mileage']; if(isset($_POST['Description'])) { $Description = $_POST['Description']; if(isset($_POST['Price'])) { $Price = $_POST['Price']; $Availability = $_POST['Availability']; $ID = $_POST['id']; $query = mysql_query("UPDATE stocklist SET Title = '$Title', Registration = '$Registration', Year = '$Year', Body = '$Body', Transmission = '$Transmission', Fuel = '$Fuel', Colour = '$Colour', Engine = '$Engine', Mileage = '$Mileage', Description = '$Description', Price = '$Price', Availability = '$Availability' WHERE ID = '$ID'") or die(mysql_error()); header("Location:manage.php"); } else { echo "Please ensure you have entered the Price!"; header("Location:edit.php?id=$ID"); } } else { echo "Please ensure you have entered the Description!"; header("Location:edit.php?id=$ID"); } } else { echo "Please ensure you have entered the Mileage!"; header("Location:edit.php?id=$ID"); } } else { echo "Please ensure you have entered the Engine!"; header("Location:edit.php?id=$ID"); } } else { echo "Please ensure you have entered the Colour!"; header("Location:edit.php?id=$ID"); } } else { echo "Please ensure you have entered the Fuel!"; header("Location:edit.php?id=$ID"); } } else { echo "Please ensure you have entered the Transmission!"; header("Location:edit.php?id=$ID"); } } else { echo "Please ensure you have entered the Body Type!"; header("Location:edit.php?id=$ID"); } } else { echo "Please ensure you have entered the Year/Reg!"; header("Location:edit.php?id=$ID"); } } else { echo "Please ensure you have entered the Vehicle Registration!"; header("Location:edit.php?id=$ID"); } } else { echo "Please ensure you have entered the Title!"; header("Location:edit.php"); } } ?>The problem i am facing is, when i click the submit button on the edit.php page, it will refresh the page, delete all the data with in the fields, but it still WILL NOT update the mysql database for that record!
Please help me out!
Thanx