Jump to content

[SOLVED] parse error, unexpected T_STRING (im sure its something stupid)


jhath

Recommended Posts

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();	
?>

Link to comment
Share on other sites

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();	
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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();	
?>

 

Link to comment
Share on other sites

<?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?

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.