Jump to content

[SOLVED] T_CONSTANT_ENCAPSED_STRING


Tiff

Recommended Posts

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

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.

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?

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.