Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
PHP&SQL Problems! $end error or unexpected ; error
mysql_connect("localhost","root" , "password") or die (mysql_error());
mysql_select_db("tutorial1") or die (mysql_error());
$personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']);
mysql_query("INSERT INTO personalinformation (name, age, sex) VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]')") or die(mysql_error());
echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex'].
?>```
Heres my code. Now I must say that the sex option is a select menu in the html.
The error I get is $end error. and when I add the ; at my last echo, I get unexpected ; on that last echo line, and the $end error is on the line of " ?>" which is weird.
Thanks for any help you guys can give me!
try this
<?php
mysql_connect("localhost","root" , "password" or die (mysql_error());
mysql_select_db("tutorial1" or die (mysql_error());
$personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']);
mysql_query("INSERT INTO personalinformation (name, age, sex) VALUES('$personaldata['name']', '$personaldata['age']', '$personaldata['sex']'" or die(mysql_error());
echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex'];
?>
It's because of how you are inserting them into the database. You are trying to use the array with constants meaning that instead of using $array['key'] you are doing $array[key] which reference to two different values. So just do:
mysql_query("INSERT INTO table (field, field, field) VALUES ('" . $array['key'] . "', '" . $array['key'] . "', '" . $array['key'] . "')");
That should insert it into the database correctly.