Home › Forums › JavaScript › Please help with PHP – Parse error: syntax error
- This topic is empty.
-
AuthorPosts
-
April 4, 2011 at 6:18 am #32225
DaGenius
MemberWill someone please help me?, I get the following error and I’m not sure what to do cause I have removed all empty spaces which I feel is causing the error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:xampphtdocswsjobsregister.php on line 55
The PHP code is below:
if($_POST) {
if($_POST == $_POST) {
$checksql = "SELECT * FROM users WHERE username = '" . $_POST . "'";
$checkresult = mysql_query($checksql);
$checknumrows = mysql_num_rows($checkresult);
if($checknumrows == 1) {
header("Location: " . $config_basedir . "register.php?error=taken");
}
else {
for($i = 0; $i < 16; $i++) {
$randomstring .= chr(mt_rand(32,126));
}
$activateurl = "http://localhost/wsjobs/activate.php";
$activationcode = urlencode($randomstring);
$verifyemail = urlencode($_POST);
$validusername = $_POST;
$sql = "INSERT INTO users(username, password, email, activationcode, active) VALUES('" . $_POST . "', '" . $_POST . "', '" . $_POST . "', '" . addslashes($randomstring) . "', 'N')";
mysql_query($sql);
$to = trim($email);
$subject = "[Whitestone Jobs] Activate Your Account";
$headers = <<From: Whitestone Jobs
Content-Type: text/plain;
MESSAGE;
$msg = <<Hi $validusername,
Please click on the following link to activate your new account:
$activateurl?email=$verifyemail&verify=$activationcode
If you have any questions, please send an email to [email protected]
--
Thanks!
Site Administrator
www.whitestonejobs.com
MAILMSG;
mail($to, $subject, $msg, $headers);
require("header.php");
echo "A link has been emailed to the address you provided. Please follow the link in the email to validate your account.";
}
else {
header("Location: " . $config_basedir . "register.php?error=pass");
}
else {
require("header.php");
switch($_GET) { //line 55
case "pass":
echo "Passwords do not match!";
break;
case "taken":
echo "Username taken, please use another.";
break;
case "no":
echo "Incorrect login details!";
break;
}
}
}
}
?>
April 4, 2011 at 7:53 am #52351TT_Mark
MemberWhat is on line 55?
April 4, 2011 at 7:58 am #52352Historical Forums User
ParticipantInstead if saying switch($_GET), you should really declare this variable differently first.
Try this instead:
$error = isset ($_GET) ? mysql_escape_string($_GET) : “”;You will then have escaped data inside $error if $_GET is set, else you will have a empty variable. Then go on to the switch, where you use $error instead of $_GET. ;)
April 4, 2011 at 11:44 am #52336DaGenius
MemberThis is what is line 55
switch($_GET) {
April 4, 2011 at 5:25 pm #52281TT_Mark
MemberEugh….sorry…that’s me not reading your original post properly.
Like adrenalinfeed says, it’s quite possible something dodgy is being passed into the $_GET variable. Or, your header.php file could contain some unclosed tag that causes an error to pass on into line 55
April 6, 2011 at 9:18 am #52155DaGenius
MemberI made certain changes to the code and ended up with the following error:
Parse error: syntax error, unexpected $end in C:xampphtdocswsjobsregister.php on line 158
Here is the whole code below
if($_POST) {
$problem = FALSE; // No problems so far.
// Check for each value...
if (empty($_POST)) {
$problem = TRUE;
echo 'Please enter your firstname!
';
}
if (empty($_POST)) {
$problem = TRUE;
echo 'Please enter your lastname!
';
}
if (empty($_POST)) {
$problem = TRUE;
echo 'Please enter your date of birth!
';
}
if (empty($_POST)) {
$problem = TRUE;
echo 'Please enter your profession!
';
}
if (empty($_POST)) {
$problem = TRUE;
echo 'Please enter your work experience!
';
}
if (empty($_POST)) {
$problem = TRUE;
echo 'Please enter your phone number!
';
}
if (empty($_POST)) {
$problem = TRUE;
echo 'Please enter your email address!
';
}
if (empty($_POST)) {
$problem = TRUE;
echo 'Please enter a password!
';
}
if ($_POST != $_POST) {
$problem = TRUE;
echo 'Your password did not match your confirm password!
';
}
if (!$problem) { // If there weren’t any problems...
//generate activate code and send mail
if($_POST == $_POST) {
$checksql = "SELECT * FROM users WHERE username = '" . $_POST . "'";
$checkresult = mysql_query($checksql);
$checknumrows = mysql_num_rows($checkresult);
if($checknumrows == 1) {
header("Location: " . $config_basedir . "register.php?error=taken");
}
else {
for($i = 0; $i < 16; $i++) {
$randomstring .= chr(mt_rand(32,126));
}
$activateurl = "http://localhost/wsjobs/activate.php";
$activationcode = urlencode($randomstring);
$verifyemail = urlencode($_POST);
$validusername = $_POST;
$query = "INSERT INTO users(ID, firstname, lastname, dob, profession, workexperience, phone, email, yoe, username, password, activationcode, active, expired, alertkeywords, registerdate) VALUES(0, '" . $_POST . "', '" . $_POST . "', '" . $_POST . "', '" . addslashes($randomstring) . "', 'N')";
mysqli_query($dbc, $query);
$to = trim($email);
$subject = "[Whitestone Jobs] Activate Your Account";
$headers = <<From: Whitestone Jobs
Content-Type: text/plain;
MESSAGE;
$msg = <<Hi $validusername,
Please click on the following link to activate your new account:
$activateurl?email=$verifyemail&verify=$activationcode
If you have any questions, please send an email to [email protected]
--
Thanks!
Site Administrator
www.whitestonejobs.com
MAILMSG;
mail($to, $subject, $msg, $headers);
require("header.php");
echo "A link has been emailed to the address you provided. Please follow the link in the email to validate your account.";
}
// Clear the posted values:
$_POST = array( );
} else { // Forgot a field.
print 'Please try again!
';
}
} // End of if no problems
}// End of handle form IF
?>
I will appreciate if someone can help me fix this. Thanks so much!.
April 6, 2011 at 12:20 pm #51982TT_Mark
MemberUnexpected end means that it isn’t expecting the file to end. Therefore you have an unclosed if/while/for statement somewhere
April 8, 2011 at 9:46 am #51788stefanbar
MemberHi, your error is on line 74 ($headers = <<
April 8, 2011 at 10:00 am #51769stefanbar
MemberWhen using the ‘heredoc’ string method, the closing sequence MESSAGE, MAILMSG; must occur on a line by itself and cannot be indented.
E.g.
$to = trim($email);
$subject = "[Whitestone Jobs] Activate Your Account";
$headers = <<From: Whitestone Jobs
Content-Type: text/plain;
MESSAGE; -
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.