d239113g Posted April 25, 2008 Share Posted April 25, 2008 Hi, i am building up my site, and i am testing getting data from a form and inserting it into the database, but i am keep getting an error Could not insert new record for INSERT INTO Customers (Surname, Firstname, Add, City, PostCode, email, Tel_No, Username, Password) VALUES ('bloggs','Joe','22 Somewhere Street','Anywhere','ZZZ 666Z','[email protected]','01910000000','joebloggs08','blogger') . Please try again can anybody see anything in my sql that is wrong? I have checked and double checked that column names in the database match my sql, and the form names match the $_POST['surname'] ect. <?php $hostname = "localhost"; $user = "xxxxxxxx"; $pass = "xxxxxxxx"; $database = "xxxxxxxx"; if (!($link = mysql_connect("$hostname", "$user", "$pass"))) die ("Could not connect MySQL"); if (!mysql_select_db($database)) die ("could not open database"); $surname=$_POST['surname']; $firstname=$_POST['firstname']; $address=$_POST['add']; $city=$_POST['city']; $postcode=$_POST['postcode']; $Email=$_POST['Email']; $tele=$_POST['tel']; $username=$_POST['username']; $password=$_POST['password']; $submit=$_POST['submit']; if($submit) { $msg=""; $sqlString="SELECT * FROM Customers where username ='$username'"; $result=mysql_query($sqlString)or die("Could not retrieve $sqlString "); if($myrow=mysql_fetch_row($result)) { $msg="Sorry, this user name is already in use. Please try again"; } else { $sqlString = "INSERT INTO Customers (Surname, Firstname, Add, City, PostCode, email, Tel_No, Username, Password) VALUES ('$surname','$firstname','$address','$city','$postcode','$Email','$tele','$username','$password')"; $result=mysql_query($sqlString)or die("Could not insert new record for $sqlString . Please try again "); $msg=" $user; Your registration was successful"; } } $msgbody = "Dear $firstname, \n\n"; $msgbody .= "Thank you for registering with FamilyHols.co.uk."; $msgbody .= "You have been successful in your application."; $msgbody .= " \n"; $msgbody .= "The username you requested was: $username\n"; $msgbody .= "Your password is: $password \n"; $msgbody .= " \n"; $msgbody .= "Please use the details above to login into FamilyHols.co.uk in order for you to purchase holidays. \n\n"; mail("$Email", "Your login details!", "$msgbody") ?> Link to comment https://forums.phpfreaks.com/topic/102943-solved-insert-into-not-working/ Share on other sites More sharing options...
AndyB Posted April 25, 2008 Share Posted April 25, 2008 ADD is a MySQL reserved word. Avoid using reserved words as table names or field names. http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Link to comment https://forums.phpfreaks.com/topic/102943-solved-insert-into-not-working/#findComment-527424 Share on other sites More sharing options...
d239113g Posted April 25, 2008 Author Share Posted April 25, 2008 Cheers working now, that was the problem Link to comment https://forums.phpfreaks.com/topic/102943-solved-insert-into-not-working/#findComment-527432 Share on other sites More sharing options...
yzerman Posted April 26, 2008 Share Posted April 26, 2008 additionally, using `fieldname` in your queries will save a lot of heartache down the line as some people use reserved names as field names. Link to comment https://forums.phpfreaks.com/topic/102943-solved-insert-into-not-working/#findComment-527522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.