Jump to content

Inserting PHP data from a form into a database problem


steve490

Recommended Posts

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 :)

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."')");

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.