jhath Posted January 30, 2008 Share Posted January 30, 2008 I'm new to php and sql, and I've been able to work out all my bugs so far but this one. I'm getting an unexpected T_STRING error, and i dont know how to get rid of it... It says its on line 6, which is the "$First Name=$_POST['First Name'];" line... Any help you could give me would be very much appreciated! <?php require_once('auth.php'); require_once ('db.php'); // Get values from form $First Name=$_POST['First Name']; $Last Name=$_POST['Last Name']; $Group ID=$_POST['Group ID']; $Home Phone=$_POST['Home Phone']; $Cell Phone=$_POST['Cell Phone']; $Work Phone=$_POST['Work Phone']; $Address=$_POST['Address']; $City=$_POST['City']; $State=$_POST['State']; $Zip=$_POST['Zip']; $Email=$_POST['Email']; $Birthday=$_POST['Birthday']; $Anniversiary=$_POST['Anniversiary']; $Spouse=$_POST['Spouse']; $Child1=$_POST['Child1']; $Child1 DOB=$_POST['Child1 DOB']; $Child2=$_POST['Child2']; $Child2 DOB=$_POST['Child2 DOB']; $Child3=$_POST['Child3']; $Child3 DOB=$_POST['Child3 DOB']; $Child4=$_POST['Child4']; $Child4 DOB=$_POST['Child4 DOB']; $Child5=$_POST['Child5']; $Child5 DOB=$_POST['Child5 DOB']; $Child6=$_POST['Child6']; $Child6 DOB=$_POST['Child6 DOB']; $Extra=$_POST['Extra']; // Insert data into mysql $sql="INSERT INTO care (First Name, Last Name, Group ID, Home Phone, Cell Phone, Work Phone, Address, City, State, Zip, Email, Birthday, Anniversiary, Spouse, Child1, Child1 DOB, Child2, Child2DOB, Child3, Child3 DOB, Child4, Child4 DOB, Child5, Child5 DOB, Child6, Child6 DOB, Extra) VALUES ('$First Name', '$Last Name', '$Group ID', '$Home Phone', '$Cell Phone', '$Work Phone', '$Address', '$City', '$State', '$Zip', '$Email', '$Birthday', '$Anniversiary', '$Spouse', '$Child1', '$Child1 DOB', '$Child2', '$Child2 DOB', '$Child3', '$Child3 DOB', '$Child4', '$Child4 DOB', '$Child5', '$Child5 DOB', '$Child6', '$Child6 DOB', '$Extra')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "<BR>"; echo "<a href='/care/add.php'>Add another</a>"; } else { echo "ERROR"; } // close connection mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/88505-solved-parse-error-unexpected-t_string-im-sure-its-something-stupid/ Share on other sites More sharing options...
rhodesa Posted January 30, 2008 Share Posted January 30, 2008 You can't have spaces in your variable names, try using an underscore...like so: $First_Name=$_POST['First Name']; Quote Link to comment https://forums.phpfreaks.com/topic/88505-solved-parse-error-unexpected-t_string-im-sure-its-something-stupid/#findComment-453062 Share on other sites More sharing options...
jhath Posted January 30, 2008 Author Share Posted January 30, 2008 alright, that solves that, but now i just get an "Error" return.. heres the new code... any ideas? <?php require_once('auth.php'); require_once ('db.php'); // Get values from form $First_Name=$_POST['First Name']; $Last_Name=$_POST['Last Name']; $Group_ID=$_POST['Group ID']; $Home_Phone=$_POST['Home Phone']; $Cell_Phone=$_POST['Cell Phone']; $Work_Phone=$_POST['Work Phone']; $Address=$_POST['Address']; $City=$_POST['City']; $State=$_POST['State']; $Zip=$_POST['Zip']; $Email=$_POST['Email']; $Birthday=$_POST['Birthday']; $Anniversiary=$_POST['Anniversiary']; $Spouse=$_POST['Spouse']; $Child1=$_POST['Child1']; $Child1_DOB=$_POST['Child1 DOB']; $Child2=$_POST['Child2']; $Child2_DOB=$_POST['Child2 DOB']; $Child3=$_POST['Child3']; $Child3_DOB=$_POST['Child3 DOB']; $Child4=$_POST['Child4']; $Child4_DOB=$_POST['Child4 DOB']; $Child5=$_POST['Child5']; $Child5_DOB=$_POST['Child5 DOB']; $Child6=$_POST['Child6']; $Child6_DOB=$_POST['Child6 DOB']; $Extra=$_POST['Extra']; // Insert data into mysql $sql="INSERT INTO care (First Name, Last Name, Group ID, Home Phone, Cell Phone, Work Phone, Address, City, State, Zip, Email, Birthday, Anniversiary, Spouse, Child1, Child1 DOB, Child2, Child2DOB, Child3, Child3 DOB, Child4, Child4 DOB, Child5, Child5 DOB, Child6, Child6 DOB, Extra) VALUES ('$First_Name', '$Last_Name', '$Group ID', '$Home_Phone', '$Cell_Phone', '$Work_Phone', '$Address', '$City', '$State', '$Zip', '$Email', '$Birthday', '$Anniversiary', '$Spouse', '$Child1', '$Child1_DOB', '$Child2', '$Child2_DOB', '$Child3', '$Child3_DOB', '$Child4', '$Child4_DOB', '$Child5', '$Child5_DOB', '$Child6', '$Child6_DOB', '$Extra')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "<BR>"; echo "<a href='/care/add.php'>Add another</a>"; } else { echo "ERROR"; } // close connection mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/88505-solved-parse-error-unexpected-t_string-im-sure-its-something-stupid/#findComment-453067 Share on other sites More sharing options...
Philip Posted January 30, 2008 Share Posted January 30, 2008 $result=mysql_query($sql); add an "or die" statement: $result=mysql_query($sql) or die(mysql_error()); this always helps when testing out code. Quote Link to comment https://forums.phpfreaks.com/topic/88505-solved-parse-error-unexpected-t_string-im-sure-its-something-stupid/#findComment-453069 Share on other sites More sharing options...
rhodesa Posted January 30, 2008 Share Posted January 30, 2008 Well, your query is failing. Most likely it's due to an 'illegal' character in one of the POST values. Whenever are doing an INSERT/UPDATE to mysql, you should use mysql_real_escape_string on every value. So here is a start: <?php require_once('auth.php'); require_once ('db.php'); // Get values from form $First_Name=mysql_real_escape_string($_POST['First Name']); $Last_Name=mysql_real_escape_string($_POST['Last Name']); $Group_ID=mysql_real_escape_string($_POST['Group ID']); ..... Quote Link to comment https://forums.phpfreaks.com/topic/88505-solved-parse-error-unexpected-t_string-im-sure-its-something-stupid/#findComment-453073 Share on other sites More sharing options...
jhath Posted January 30, 2008 Author Share Posted January 30, 2008 Added both of those, and changed everything from the " " to the "_" even in the actual db, the insert.php, and the html form... here is the error im getting... Unknown column 'Child6_DOB' in 'field list' What does that mean??? Child6_DOB is spelled correctly in the db, as well as in the html form (which i can show you that if that would help) and in here... what gives? Here is the updated code <?php require_once('auth.php'); require_once ('db.php'); // Get values from form $First_Name=mysql_real_escape_string($_POST['First_Name']); $Last_Name=mysql_real_escape_string($_POST['Last_Name']); $Group_ID=mysql_real_escape_string($_POST['Group_ID']); $Home_Phone=mysql_real_escape_string($_POST['Home_Phone']); $Cell_Phone=mysql_real_escape_string($_POST['Cell_Phone']); $Work_Phone=mysql_real_escape_string($_POST['Work_Phone']); $Address=mysql_real_escape_string($_POST['Address']); $City=mysql_real_escape_string($_POST['City']); $State=mysql_real_escape_string($_POST['State']); $Zip=mysql_real_escape_string($_POST['Zip']); $Email=mysql_real_escape_string($_POST['Email']); $Birthday=mysql_real_escape_string($_POST['Birthday']); $Anniversiary=mysql_real_escape_string($_POST['Anniversiary']); $Spouse=mysql_real_escape_string($_POST['Spouse']); $Child1=mysql_real_escape_string($_POST['Child1']); $Child1_DOB=mysql_real_escape_string($_POST['Child1_DOB']); $Child2=mysql_real_escape_string($_POST['Child2']); $Child2_DOB=mysql_real_escape_string($_POST['Child2_DOB']); $Child3=mysql_real_escape_string($_POST['Child3']); $Child3_DOB=mysql_real_escape_string($_POST['Child3_DOB']); $Child4=mysql_real_escape_string($_POST['Child4']); $Child4_DOB=mysql_real_escape_string($_POST['Child4_DOB']); $Child5=mysql_real_escape_string($_POST['Child5']); $Child5_DOB=mysql_real_escape_string($_POST['Child5_DOB']); $Child6=mysql_real_escape_string($_POST['Child6']); $Child6_DOB=mysql_real_escape_string($_POST['Child6_DOB']); $Extra=mysql_real_escape_string($_POST['Extra']); // Insert data into mysql $sql="INSERT INTO care (First_Name, Last_Name, Group_ID, Home_Phone, Cell_Phone, Work_Phone, Address, City, State, Zip, Email, Birthday, Anniversiary, Spouse, Child1, Child1_DOB, Child2, Child2_DOB, Child3, Child3_DOB, Child4, Child4_DOB, Child5, Child5_DOB, Child6, Child6_DOB, Extra) VALUES ('$First_Name', '$Last_Name', '$Group_ID', '$Home_Phone', '$Cell_Phone', '$Work_Phone', '$Address', '$City', '$State', '$Zip', '$Email', '$Birthday', '$Anniversiary', '$Spouse', '$Child1', '$Child1_DOB', '$Child2', '$Child2_DOB', '$Child3', '$Child3_DOB', '$Child4', '$Child4_DOB', '$Child5', '$Child5_DOB', '$Child6', '$Child6_DOB', '$Extra')"; $result=mysql_query($sql) or die(mysql_error()); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "<BR>"; echo "<a href='/care/add.php'>Add another</a>"; } else { echo "ERROR"; } // close connection mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/88505-solved-parse-error-unexpected-t_string-im-sure-its-something-stupid/#findComment-453122 Share on other sites More sharing options...
Philip Posted January 30, 2008 Share Posted January 30, 2008 <?php //... $sql="INSERT INTO `care` (`First_Name`, `Last_Name`, `Group_ID`, `Home_Phone`, `Cell_Phone`, `Work_Phone`, `Address`, `City`, `State`, `Zip`, `Email`, `Birthday`, `Anniversiary`, `Spouse`, `Child1`, `Child1_DOB`, `Child2`, `Child2_DOB`, `Child3`, `Child3_DOB`, `Child4`, `Child4_DOB`, `Child5`, `Child5_DOB`, `Child6`, `Child6_DOB`, `Extra`) VALUES ('$First_Name', '$Last_Name', '$Group_ID', '$Home_Phone', '$Cell_Phone', '$Work_Phone', '$Address', '$City', '$State', '$Zip', '$Email', '$Birthday', '$Anniversiary', '$Spouse', '$Child1', '$Child1_DOB', '$Child2', '$Child2_DOB', '$Child3', '$Child3_DOB', '$Child4', '$Child4_DOB', '$Child5', '$Child5_DOB', '$Child6', '$Child6_DOB', '$Extra')"; echo $sql."<br />"; $result=mysql_query($sql) or die(mysql_error()); //... ?> Please post what it prints [the query]... and you're 100% sure you have a column 'Child6_DOB' in the DB? Quote Link to comment https://forums.phpfreaks.com/topic/88505-solved-parse-error-unexpected-t_string-im-sure-its-something-stupid/#findComment-453125 Share on other sites More sharing options...
jhath Posted January 30, 2008 Author Share Posted January 30, 2008 yea... although I'm not exactly sure by what you mean "what it prints out" Here's two screenies tho... Quote Link to comment https://forums.phpfreaks.com/topic/88505-solved-parse-error-unexpected-t_string-im-sure-its-something-stupid/#findComment-453130 Share on other sites More sharing options...
rhodesa Posted January 30, 2008 Share Posted January 30, 2008 In your database, it looks like there is a space after the underscore in Child6_DOB Quote Link to comment https://forums.phpfreaks.com/topic/88505-solved-parse-error-unexpected-t_string-im-sure-its-something-stupid/#findComment-453132 Share on other sites More sharing options...
jhath Posted January 30, 2008 Author Share Posted January 30, 2008 ohhhhhhhh that sucks... works now! thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/88505-solved-parse-error-unexpected-t_string-im-sure-its-something-stupid/#findComment-453137 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.