rogerse Posted December 16, 2009 Share Posted December 16, 2009 Hi there, I have written a page which is meant to allow a user to enter details of a new car for sale (via a form), and then the submission of this form should add the details to the database. As far as I can see all the code is correct, yet I don't get a new entry. The Form ------------ <form action="addCar.php" method="post"> Category: <select name="Category"> <option>Classic</option> <option>Modern</option> <option>Range_Rover</option> </select> <br /> Make:<input type="text" name="Make" value=""><br /> Model: <input type="text" name="Model" value=""><br /> Reg Year: <input type="text" name="Reg_Year" value=""><br /> Reg Letter: <input type="text" name="Reg_Letter" value=""><br /> Mileage: <input type="text" name="Mileage" value=""><br /> Price: <input type="text" name="Price" value=""><br /> Price Alternate: <input type="text" name="Price_Alternate" value=""><br /> Description: <textarea cols="60" name="Description" rows="4"></textarea><br /> Image 1: <input type="text" name="Image1" value="<? echo $Image1; ?>"><br /> Image 2: <input type="text" name="Image2" value="<? echo $Image2; ?>"><br /> Image 3: <input type="text" name="Image3" value="<? echo $Image3; ?>"><br /> Image 4: <input type="text" name="Image4" value="<? echo $Image4; ?>"><br /> <input type="Submit" value="Add" name="send"> </form> addCar.php -------------- <?php $Category=$_POST['Category']; $Make=$_POST['Make']; $Model=$_POST['Model']; $Reg_Year=$_POST['Reg_Year']; $Reg_Letter=$_POST['Reg_Letter']; $Mileage=$_POST['Mileage']; $Price=$_POST['Price']; $Price_Alternate=$_POST['Price_Alternate']; $Description=$_POST['Description']; $Image1=$_POST['Image1']; $Image2=$_POST['Image2']; $Image3=$_POST['Image3']; $Image4=$_POST['Image4']; $username="usrname"; $password="pswd"; $database="dbName"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="INSERT INTO cars (ID, Category, Make, Model, Reg_Year, Reg_Letter, Mileage, Price, Price_Alternate, Description, Image1, Image2, Image3, Image4) VALUES ('','$Category,'$Make','$Model','$Reg_Year','$Reg_Letter,'$Mileage','$Price','$Price_Alternate','$Description','$Image1','$Image2','$Image3','$Image4')"; mysql_query($query); echo "Car Added"; mysql_close(); ?> Is this a case of "can't see the wood for the tree's"? Am I missing something glaringly obvious? Cheers guys, Ed Link to comment https://forums.phpfreaks.com/topic/185304-problem-adding-new-entry-to-a-database/ Share on other sites More sharing options...
nafetski Posted December 16, 2009 Share Posted December 16, 2009 In your SQL...missing a single quote after $category and $Reg_letter (in your values area). Let me know if it works! Link to comment https://forums.phpfreaks.com/topic/185304-problem-adding-new-entry-to-a-database/#findComment-978309 Share on other sites More sharing options...
btherl Posted December 16, 2009 Share Posted December 16, 2009 Change this line mysql_query($query); to mysql_query($query) or die("Error in $query: " . mysql_last_error()); It will tell you if there's a problem with the query. I think nafetski has picked up the issue already though. Link to comment https://forums.phpfreaks.com/topic/185304-problem-adding-new-entry-to-a-database/#findComment-978312 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.