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 Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/ Share on other sites More sharing options...
Tiff Posted February 24, 2007 Author Share Posted February 24, 2007 Pleease help me Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/#findComment-192992 Share on other sites More sharing options...
Tiff Posted February 25, 2007 Author Share Posted February 25, 2007 pweease =[ i cant figure it out Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/#findComment-193324 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'] Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/#findComment-193329 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. Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/#findComment-193331 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? Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/#findComment-193340 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. Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/#findComment-193341 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']) { Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/#findComment-193351 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. Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/#findComment-193352 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) ?> Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/#findComment-193359 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. Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/#findComment-193361 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']) Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/#findComment-193563 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. Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/#findComment-193565 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 Link to comment https://forums.phpfreaks.com/topic/39921-solved-t_constant_encapsed_string/#findComment-193570 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.