Twill1989 Posted December 26, 2006 Share Posted December 26, 2006 Hi,I'm the webmaster for a organization at my school. I've been working on developing a online enlistment form for our organization, but I can't seem to get the coding correct. I worked on it for months and I have had no progress at all. This is the error I'm constantly getting: Parse error: parse error, expecting `']'' in ... on line 12Here is the insert file:<?php$con = mysql_connect("...","...","...");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("...", $con);$sql="INSERT INTO person (Name, Phone Number, Email Address, Shirt Size, Grade, HonorsAP, GPA, Transportation, Why)VALUES('$_POST[Name]','$_POST[Phone Number]','$_POST','$_POST[shirt Size]','$_POST[Grade]','$_POST[HonorsAP]','$_POST[GPA]','$_POST[Transportation]','$_POST[Why]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added";mysql_close($con)?> Can anyone tell me what I'm doing wrong? I can get the code to work if I use a smaller number of text fields. For example, if I have only four or five things to fill in, everything works fine. But with the nine I have, I always get the above error. Thanks Link to comment Share on other sites More sharing options...
reportingsjr Posted December 26, 2006 Share Posted December 26, 2006 You need to add single quotes to the inside of the post variables. E.G.: $_POST['Name'] Link to comment Share on other sites More sharing options...
Twill1989 Posted December 26, 2006 Author Share Posted December 26, 2006 Thanks, but now I'm getting this error: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in ... on line 12 Link to comment Share on other sites More sharing options...
reportingsjr Posted December 26, 2006 Share Posted December 26, 2006 Okay then, try doing this to all post variables:{$_POST['Name']} Link to comment Share on other sites More sharing options...
Twill1989 Posted December 26, 2006 Author Share Posted December 26, 2006 I tried, another error: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Number, Email Address, Shirt Size, Grade, HonorsAP, GPA, TranspoHere is what the new insert file looks like: <?php$con = mysql_connect("...","...","...");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("...", $con);$sql="INSERT INTO person (Name, Phone Number, Email Address, Shirt Size, Grade, HonorsAP, GPA, Transportation, Why)VALUES('{$_POST['Name']}','{$_POST['Phone Number']}','{$_POST['Email Address']}','{$_POST['Shirt Size']}','{$_POST['Grade']}','{$_POST['HonorsAP']}','{$_POST['GPA']}','{$_POST['Transportation']}','{$_POST['Why']}')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added";mysql_close($con)?> Link to comment Share on other sites More sharing options...
jesh Posted December 27, 2006 Share Posted December 27, 2006 It may be because your column name has a space in it. Either update your column names so that there aren't any spaces (e.g. "PhoneNumber") or - some MySQL expert, please correct me if I'm wrong - try putting ` around the column names in your query: INSERT INTO person (Name, `Phone Number`, `Email Address`, `Shirt Size`, Grade, HonorsAP, GPA, Transportation, Why)VALUES Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now