barryflood22 Posted April 9, 2007 Share Posted April 9, 2007 I have created a form that will input new records to an sql table, but it wont work. the database connects fine, iv already tested that, but for some reason i cant get it to add new records to the table. please help!!! ---form page---- <form action="insert.php" method="post"> Name: <input type="text" name="Name"><br> Address: <input type="text" name="Address"><br> Postcode: <input type="text" name="Postcode"><br> Telephone Number: <input type="text" name="Telephone_Number"><br> Email Address: <input type="text" name="Email_Address"><br> Type: <input type="text" name="Type"><br> Appointment: <input type="text" name="Appointment"><br> <input type="Submit"> </form> DATA FROM ABOVE WILL NOW IMPORT TO THE BELOW PAGE --- insert page ---- <? $username="admin"; $server="localhost"; $password="admin"; $database="hoff_real_estate"; $Name=$_POST['Name']; $Address=$_POST['Address']; $Postcode=$_POST['Postcode']; $Telephone_Number=$_POST['Telephone_Number']; $Email_Address=$_POST['Email_Address']; $Type=$_POST['Type']; $Appointment=$_POST['Appointment']; $query = "INSERT INTO "customers" VALUES ('$Name','$Address','$Postcode','$Telephone_Number','$Email_Address','$Type','$Appointment')"; mysql_connect($server,$username,$password) or die( "Unable to select table"); @mysql_select_db($database) or die( "Unable to select database"); mysql_query($query); mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/46301-adding-records-to-sql-database-help/ Share on other sites More sharing options...
esukf Posted April 9, 2007 Share Posted April 9, 2007 <?php $query = "INSERT INTO customers (Name, Address , Postcode, Telephone_Number, Email_Address, Type, Appointment) VALUES ('$Name','$Address','$Postcode','$Telephone_Number','$Email_Address','$Type','$Appointment')"; ?> Name, Address etc are the field name in your database. Link to comment https://forums.phpfreaks.com/topic/46301-adding-records-to-sql-database-help/#findComment-225253 Share on other sites More sharing options...
barryflood22 Posted April 9, 2007 Author Share Posted April 9, 2007 so i should take away the $ symbols??? Link to comment https://forums.phpfreaks.com/topic/46301-adding-records-to-sql-database-help/#findComment-225256 Share on other sites More sharing options...
barryflood22 Posted April 9, 2007 Author Share Posted April 9, 2007 nope, still not working Link to comment https://forums.phpfreaks.com/topic/46301-adding-records-to-sql-database-help/#findComment-225260 Share on other sites More sharing options...
esukf Posted April 9, 2007 Share Posted April 9, 2007 Your original error was that you had double quotes around customers. $query = "INSERT INTO customers VALUES ('$Name','$Address','$Postcode','$Telephone_Number','$Email_Address','$Type','$Appointment')"; It is preferred to list out the field name for which the values are to be inserted. INSERT INTO table (fieldname1, fieldname2, fieldname3) VALUES ('value1', 'value2', 'value3'); Link to comment https://forums.phpfreaks.com/topic/46301-adding-records-to-sql-database-help/#findComment-225264 Share on other sites More sharing options...
barryflood22 Posted April 9, 2007 Author Share Posted April 9, 2007 iv changed it to that, but its still not working. <? $username="admin"; $server="localhost"; $password="admin"; $database="hoff_real_estate"; $Name=$_POST['Name']; $Address=$_POST['Address']; $Postcode=$_POST['Postcode']; $Telephone_Number=$_POST['Telephone_Number']; $Email_Address=$_POST['Email_Address']; $Type=$_POST['Type']; $Appointment=$_POST['Appointment']; $query = "INSERT INTO customers (Name, Address , Postcode, Telephone_Number, Email_Address, Type, Appointment) VALUES ('$Name','$Address','$Postcode','$Telephone_Number','$Email_Address','$Type','$Appointment')"; mysql_connect($server,$username,$password) or die( "Unable to select table"); @mysql_select_db($database) or die( "Unable to select database"); mysql_query($query); mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/46301-adding-records-to-sql-database-help/#findComment-225268 Share on other sites More sharing options...
esukf Posted April 9, 2007 Share Posted April 9, 2007 Do the field names actually match those in your database?? I guessed them from the naming of you variables. Try replace the following into your code and see what errors you get. <?php mysql_connect($server,$username,$password) or die(mysql_error()); @mysql_select_db($database) or die(mysql_error()); mysql_query($query) or die(mysql_error()); mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/46301-adding-records-to-sql-database-help/#findComment-225278 Share on other sites More sharing options...
barryflood22 Posted April 9, 2007 Author Share Posted April 9, 2007 i ran this : <? $username="admin"; $server="localhost"; $password="admin"; $database="hoff_real_estate"; $Name=$_POST['Name']; $Address=$_POST['Address']; $Postcode=$_POST['Postcode']; $Telephone_Number=$_POST['Telephone_Number']; $Email_Address=$_POST['Email_Address']; $Type=$_POST['Type']; $Appointment=$_POST['Appointment']; $query = "INSERT INTO customers (Name, Address , Postcode, Telephone_Number, Email_Address, Type, Appointment) VALUES ('$Name','$Address','$Postcode','$Telephone_Number','$Email_Address','$Type','$Appointment')"; mysql_connect($server,$username,$password) or die(mysql_error()); @mysql_select_db($database) or die(mysql_error()); mysql_query($query) or die(mysql_error()); mysql_close(); ?> and it didnt make a difference Link to comment https://forums.phpfreaks.com/topic/46301-adding-records-to-sql-database-help/#findComment-225284 Share on other sites More sharing options...
barryflood22 Posted April 9, 2007 Author Share Posted April 9, 2007 this is my phpmyadmin window http://img133.imageshack.us/img133/9661/phpmyadminff3.jpg Link to comment https://forums.phpfreaks.com/topic/46301-adding-records-to-sql-database-help/#findComment-225296 Share on other sites More sharing options...
esukf Posted April 9, 2007 Share Posted April 9, 2007 Did it give you any errors at all? echo $query; Add the above line right after $query = "....." and paste the sql query here. The only other thing i can think of is that you are trying to insert an invalid date format. mysql date should be YYYY-MM-DD Link to comment https://forums.phpfreaks.com/topic/46301-adding-records-to-sql-database-help/#findComment-225307 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.