Tiff Posted February 24, 2007 Share Posted February 24, 2007 I have a bit of a problem again chaps im trying to get it so it checks that all the fields are correct and that both the passwords match before entering it into the database, but i get this error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/chris/public_html/insert.php on line 52 and the code that i have done is: <?php if (!$_POST '[FirstName]' || '[LastName]' || '[Age]' || '[Password]' || '[Password2]') { die('You did not complete all of the required fields'); } elseif ($_post '[Password]' != $_post '[Password2]') { die('The passwords did not match'); } else $con = mysql_connect("-","-","-"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("chris_mydb", $con); $sql="INSERT INTO person (FirstName, LastName, Age, Password) VALUES ('$_POST[FirstName]','$_POST[LastName]','$_POST[Age]', '$_POST[Password]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 Record Added"; mysql_close($con) ?> can anyone help me? Thank you very much if you can Quote Link to comment Share on other sites More sharing options...
Tiff Posted February 24, 2007 Author Share Posted February 24, 2007 Pleease help me Quote Link to comment Share on other sites More sharing options...
Tiff Posted February 25, 2007 Author Share Posted February 25, 2007 pweease =[ i cant figure it out Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted February 25, 2007 Share Posted February 25, 2007 Lets start with changing everywhere that you put stuff like: $_POST '[variable]' to $_POST['variable'] Quote Link to comment Share on other sites More sharing options...
superuser2 Posted February 25, 2007 Share Posted February 25, 2007 Ok: a)Your insert if referencing variables like $_POST[firstName]. You can't do that, you need to use quotes, and you need to wrap the whole variable in curly braces. So you would say {$_POST['firstName']}. That should work for you. b)As to your parse error, try putting a semicolon on that last mysql_close, might help. After that, if anything is still not working, please don't hesitate to ask for help. Quote Link to comment Share on other sites More sharing options...
Tiff Posted February 25, 2007 Author Share Posted February 25, 2007 Sorry to be a hassle but its now saying unexpected '{' and this is what i changed it to 1 second if {$_POST ['FirstName']|| ['LastName'] || ['Age'] || ['Password'] || ['Password2']} or did i do that wrong? Quote Link to comment Share on other sites More sharing options...
superuser2 Posted February 25, 2007 Share Posted February 25, 2007 Oh sorry, not there. Just inside double quotes. Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted February 25, 2007 Share Posted February 25, 2007 That line should read: if ($_POST['FirstName'] || $_POST['LastName'] || $_POST['Age'] || $_POST['Password'] || $_POST['Password2']) { Quote Link to comment Share on other sites More sharing options...
superuser2 Posted February 25, 2007 Share Posted February 25, 2007 That's correct. I was just referring to the mysql query. Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted February 25, 2007 Share Posted February 25, 2007 Good call superuser. *******************MODIFIED********************** <?php if (!$_POST['FirstName'] || !$_POST['LastName'] || !$_POST['Age'] || !$_POST['Password'] || !$_POST['Password2']) { die('You did not complete all of the required fields'); } elseif ($_post ['Password'] != $_post ['Password2']) { die('The passwords did not match'); } else $con = mysql_connect("host","username","password") or die('Could not connect to database' .mysql_error()); mysql_select_db("chris_mydb", $con) or die('Failed to select db.' .mysql_error()); $sql="INSERT INTO person (FirstName, LastName, Age, Password) VALUES (".$_POST['FirstName'].",".$_POST['LastName'].",".$_POST['Age'].",".$_POST['Password'].")"; $result = mysql_query($sql,$con) or die('Mysql Query Failed. '.mysql_error()); echo "1 Record Added"; mysql_close($con) ?> Quote Link to comment Share on other sites More sharing options...
superuser2 Posted February 25, 2007 Share Posted February 25, 2007 You'll still get an error for unexpected T_CONSTANT_ESCAPED STRING. In your mysql query, wrap those POST variables in curly braces. Quote Link to comment Share on other sites More sharing options...
Tiff Posted February 25, 2007 Author Share Posted February 25, 2007 OK i have 1 more problem and then i will leave you alone =] I want it to compare the two passwords and make sure there right but so far it hasnt, soooo, have i done the code right elseif ($_post ['Password'] != $_post ['Password2']) Quote Link to comment Share on other sites More sharing options...
Orio Posted February 25, 2007 Share Posted February 25, 2007 Capital letters for post: elseif ($_POST['Password'] != $_POST['Password2']) Orio. Quote Link to comment Share on other sites More sharing options...
Tiff Posted February 25, 2007 Author Share Posted February 25, 2007 yay =] I love you all! I really do =] Case solved Quote Link to comment 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.