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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.