Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP Error

  • 02-04-2010 6:13pm
    #1
    Registered Users, Registered Users 2 Posts: 416 ✭✭


    Am trying to get some php code working for a college project,
    would appreciate it any knows how to fix this error,

    Its for a login system,
    the part of it thats having issues is the register user part,

    the error is;

    ( ! ) Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\ch16\register.php on line 67
    the code is

    // Send the email:
    $body = "Thank you for registering at mysite. To activate your account, please click on this link:\n\n";
    $body . = BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a";


Comments

  • Subscribers Posts: 9,716 ✭✭✭CuLT


    There should be no space between . and = on your second line there.

    Both characters together make the operator.


  • Registered Users, Registered Users 2 Posts: 416 ✭✭thecelt


    thanks, changed that but its still giving the same error!


  • Subscribers Posts: 9,716 ✭✭✭CuLT


    Hmm, that would have given you trouble eventually anyway :)

    Probably something a little bit earlier in the code so, like a missing semi-colon, or an unclosed bracket.


  • Registered Users, Registered Users 2 Posts: 416 ✭✭thecelt


    This is the whole file, cant seem to see what could be missing,
    if anything jumps out at you, let me know


    <?php
    require_once ('admin/config.inc.php');
    $page_title = 'Register';
    include ('admin/header.html');

    if (isset($_POST)) { // Handle the form.
    //require_once (MYSQL);
    require_once ('admin/mysqli_connect.php');
    // Trim all the incoming data:
    $trimmed = array_map('trim', $_POST);

    // Assume invalid values:
    $fn = $ln = $e = $p = FALSE;

    // Check for a first name:
    if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed)) {
    $fn = mysqli_real_escape_string ($dbc, $trimmed);
    } else {
    echo '<p class="error">Please enter your first name!</p>';
    }

    // Check for a last name:
    if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed)) {
    $ln = mysqli_real_escape_string ($dbc, $trimmed);
    } else {
    echo '<p class="error">Please enter your last name!</p>';
    }

    // Check for an email address:
    if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed)) {
    $e = mysqli_real_escape_string ($dbc, $trimmed);
    } else {
    echo '<p class="error">Please enter a valid email address!</p>';
    }

    // Check for a password and match against the confirmed password:
    if (preg_match ('/^\w{4,20}$/', $trimmed) ) {
    if ($trimmed == $trimmed) {
    $p = mysqli_real_escape_string ($dbc, $trimmed);
    } else {
    echo '<p class="error">Your password did not match the confirmed password!</p>';
    }
    } else {
    echo '<p class="error">Please enter a valid password!</p>';
    }

    if ($fn && $ln && $e && $p) { // If everything's OK...

    // Make sure the email address is available:
    $q = "SELECT user_id FROM users WHERE email='$e'";
    $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));

    if (mysqli_num_rows($r) == 0) { // Available.

    // Create the activation code:
    $a = md5(uniqid(rand(), true));

    // Add the user to the database:
    $q = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', SHA1('$p'), '$fn', '$ln', '$a', NOW() )";
    $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: .mysqli_error($dbc));

    if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.

    // Send the email:
    $body = "Thank you for registering at mysite. To activate your account, please click on this link:\n\n";
    $body .= BASE_URL .'activate.php?x='.urlencode($e)."&y=$a";

    mail($trimmed, 'Registration Confirmation', $body, 'From: admin@sitename.com');

    // Finish the page:
    echo "<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>";
    include ('includes/footer.html'); // Include the HTML footer.
    exit(); // Stop the page.

    } else { // If it did not run OK.
    echo "<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';
    }

    } else { // The email address is not available.
    echo '<p class="error">That email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.</p>"";
    }

    } else { // If one of the data tests failed.
    echo '<p class="error">Please re-enter your passwords and try again.</p>';
    }

    mysqli_close($dbc);

    } // End of the main Submit conditional.
    ?>

    <h1>Register</h1>
    <form action="register.php" method="post">
    <fieldset>

    <p><b>First Name:</b> <input type="text" name="first_name" size="20" maxlength="20" value="<?php if (isset($trimmed)) echo $trimmed; ?>" /></p>

    <p><b>Last Name:</b> <input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($trimmed)) echo $trimmed; ?>" /></p>

    <p><b>Email Address:</b> <input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($trimmed)) echo $trimmed; ?>" /> </p>

    <p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="20" /> <small>Use only letters, numbers, and the underscore. Must be between 4 and 20 characters long.</small></p>

    <p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p>
    </fieldset>

    <div align="center"><input type="submit" name="submit" value="Register" /></div>
    <input type="hidden" name="submitted" value="TRUE" />

    </form>

    <?php // Include the HTML footer.
    include ('admin/footer.html');
    ?>


  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    You've got multiple errors, all from not closing strings properly.
    line 60:
    $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: [COLOR="blue"][B]"[/B][/COLOR].mysqli_error($dbc));
    
    line 76:
    echo [COLOR="Red"][B]"[/B][B][COLOR="Blue"]'[/COLOR][/B][/COLOR]<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';
    
    line 80:
    echo '<p class="error">That email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.</p>[COLOR="Red"][B]""[/B][/COLOR][COLOR="Blue"][B]'[/B][/COLOR];
    
    (remove parts in red, add parts in blue)
    Dunno what editor you're using, but these were pretty easy to locate in notepad++ due to code highlighting.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 416 ✭✭thecelt


    Thanks, yeah i installed notepad++ , much better had been using pspad,
    found a few errors very easily,

    came across this one,
    is this an error or does it just mean it wont work running it locally,


    An error occurred in script 'C:\xampp\htdocs\ch16\register.php' on line 69: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
    Date/Time: 4-2-2010 17:14:28


  • Closed Accounts Posts: 6,281 ✭✭✭Ricky91t


    thecelt wrote: »
    Thanks, yeah i installed notepad++ , much better had been using pspad,
    found a few errors very easily,

    came across this one,
    is this an error or does it just mean it wont work running it locally,


    An error occurred in script 'C:\xampp\htdocs\ch16\register.php' on line 69: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
    Date/Time: 4-2-2010 17:14:28


    Yep it's cause you're running it locally I'd imagine!

    You're using a function which needs to access settings in your PHP.ini file while in turn need to connect to an SMTP mail server


  • Registered Users, Registered Users 2 Posts: 416 ✭✭thecelt


    ok, thanks for your help,
    doing a hdip in computing,
    so relatively new to coding,
    working on a php project for college or trying to lol


Advertisement