Well having thought I'd got over all the hurdles of this damn database with my previous post, it seems I hadn't quite suffered enough, and have been thrown another challenge.
I have a piece of code which fills a form in with the current details of a car record.
Form
----
<form action="updatedCar.php" method="post">
<input type="hidden" name="ud_stockNumber" value="<? echo $scn; ?>">
Category: <input type="text" name="ud_Category" value="<? echo $Category; ?>">
Must be either 'Classic', 'Modern', or 'Range_Rover'<br />
Make: <input type="text" name="ud_Make" value="<? echo $Make; ?>"><br />
Model: <input type="text" name="ud_Model" value="<? echo $Model; ?>"><br />
Reg Year: <input type="text" name="ud_Reg_Year" value="<? echo $Reg_Year; ?>"><br />
Reg Letter: <input type="text" name="ud_Reg_Letter" value="<? echo $Reg_Letter; ?>"><br />
Mileage: <input type="text" name="ud_Mileage" value="<? echo $Mileage; ?>"><br />
Price: <input type="text" name="ud_Price" value="<? echo $Price; ?>"><br />
Price Alternate: <input type="text" name="ud_Price_Alternate" value="<? echo $Price_Alternate; ?>"><br />
Description: <textarea id="TextArea1" cols="60" rows="4" name="ud_Description"><? echo $Description; ?></textarea><br />
Image 1: <input type="text" name="ud_Image1" value="<? echo $Image1; ?>"><br />
Image 2: <input type="text" name="ud_Image2" value="<? echo $Image2; ?>"><br />
Image 3: <input type="text" name="ud_Image3" value="<? echo $Image3; ?>"><br />
Image 4: <input type="text" name="ud_Image4" value="<? echo $Image4; ?>"><br />
<input type="Submit" value="Update">
</form>
The idea is that the user edits anything they like within the form, and clicks Update.
This then runs updatedCar.php
<?php
$ud_stockNumber=$_GET['ud_stockNumber'];
$ud_Category=$_POST['ud_Category'];
$ud_Make=$_POST['ud_Make'];
$ud_Model=$_POST['ud_Model'];
$ud_Reg_Year=$_POST['ud_Reg_Year'];
$ud_Reg_Letter=$_POST['ud_Reg_Letter'];
$ud_Mileage=$_POST['ud_Mileage'];
$ud_Price=$_POST['ud_Price'];
$ud_Price_Alternate=$_POST['ud_Price_Alternate'];
$ud_Description=$_POST['ud_Description'];
$ud_Image1=$_POST['ud_Image1'];
$ud_Image2=$_POST['ud_Image2'];
$ud_Image3=$_POST['ud_Image3'];
$ud_Image4=$_POST['ud_Image4'];
$username="usrname";
$password="pswrd";
$database="dbName";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="UPDATE cars SET Category='$ud_Category', Make='$ud_Make', Model='$ud_Model', Reg_Year='$ud_Reg_Year', Reg_Letter='$ud_Reg_Letter', Mileage='$ud_Mileage', Price='$ud_Price', Price_Alternate='$ud_Price_Alternate', Description='$ud_Description', Image1='$ud_Image1', Image2='$ud_Image2', Image3='$ud_Image3', Image4='$ud_Image4' WHERE ID='$ud_stockNumber'";
mysql_query($query);
echo "Record Updated";
mysql_close();
?>
But the database doesn't change.
Now from my reading of the tutorials, I can't find any differences between the sample code and my code, other than variable names.
Again, I think this could be a case of staring at code for too long...
Any help will be greatly appreciated.
Ed