steve490 Posted December 22, 2009 Share Posted December 22, 2009 Hey im not sure whether this is in the wrong section but here goes, I have a problem with some code that doesn't seem to be inserting data from a form on my website to a database. I've tried so many different ways to do this the code might be untidy. i'm a bit of a noob so go easy on me haha sign_up is the DB name and signup is the table name just to clarify heres the code $email = $_POST{"email"}; $firstName = $_POST{"firstName"}; $surname = $_POST {"surname"}; $DOB = $_POST {"DOB"}; $University = $_POST {"University"}; $Art_specialty = $_POST {"Art_specialty"}; $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'pass'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'webcatc1_signup'; mysql_select_db($dbname); mysql_query("INSERT INTO sign_up (email, firstName, surname, DOB, University, Art_specialty) VALUES (".$email.",".$firstName.",".$surname.",".$DOB.",".$University.",".$Art_specialty.")"); $result = mysql_query("SELECT * FROM sign_up") or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['firstName']. " - ". $row['surname']; echo "<br />"; } echo "the results are..." .$email. "" .$firstName; echo "1 record added"; mysql_close($conn) Thanks for the help Link to comment https://forums.phpfreaks.com/topic/186031-inserting-php-data-from-a-form-into-a-database-problem/ Share on other sites More sharing options...
rajivgonsalves Posted December 22, 2009 Share Posted December 22, 2009 you do not have quotes on your insert values since it is a string it should have quotes something like this mysql_query("INSERT INTO sign_up (email, firstName, surname, DOB, University, Art_specialty) VALUES ('".$email."','".$firstName."','".$surname."','".$DOB."','".$University."','".$Art_specialty."')"); Link to comment https://forums.phpfreaks.com/topic/186031-inserting-php-data-from-a-form-into-a-database-problem/#findComment-982380 Share on other sites More sharing options...
steve490 Posted December 22, 2009 Author Share Posted December 22, 2009 Cheers that was quick and simple will remember how to do it now problem solved Link to comment https://forums.phpfreaks.com/topic/186031-inserting-php-data-from-a-form-into-a-database-problem/#findComment-982399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.