Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Please help with PHP – Parse error: syntax error

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #32225
    DaGenius
    Member

    Will 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;
    }
    }
    }
    }
    ?>











    Personal Details























    Login Details










    Categories

    Please select your job interest category








    #52351
    TT_Mark
    Member

    What is on line 55?

    #52352

    Instead 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. ;)

    #52336
    DaGenius
    Member

    This is what is line 55

    switch($_GET) {
    #52281
    TT_Mark
    Member

    Eugh….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

    #52155
    DaGenius
    Member

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











    Personal Details























    Login Details










    Categories

    Please select your job interest category







    I will appreciate if someone can help me fix this. Thanks so much!.

    #51982
    TT_Mark
    Member

    Unexpected end means that it isn’t expecting the file to end. Therefore you have an unclosed if/while/for statement somewhere

    #51788
    stefanbar
    Member

    Hi, your error is on line 74 ($headers = <<

    #51769
    stefanbar
    Member

    When 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;
Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.