SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Parse error

  1. #1
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parse error

    i have a problem to locate the parse error on this login.php below, :

    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
    in register.php on line 29

    please help me to identify, my code below :

    PHP Code:
    <?php
    session_start
    (); 
    include(
    "photoconfig.php"); 
    if(isset(
    $_POST['submit']))
    {
      if(!isset(
    $_POST['username']) || $_POST['username'] == '' || !isset($_POST['password']) || $_POST['password'] == ''|| !isset($_POST['emailaccount']) || $_POST['emailaccount'] == '')
        {
        
    header('Location: login.php?err=true'); 
        }else{
        
    $username $_POST['username'];
        
    $password $_POST['password'];
        
    $emailaccount $_POST['emailaccount'];
        
    $query "SELECT * FROM diverlist WHERE diver_name = '$username' AND diver_password = '$password'";
        
    $result mysql_query($query) or die("Register failed. " mysql_error());
        
    $numrows mysql_num_rows($result);
        if(
    $numrows !== 0){
        
    $info mysql_fetch_assoc($result);
        
    $diverid $info['diver_name'];
        
    $_SESSION[''.$diverid.''] = TRUE;
        
    $_SESSION['regresult'] = TRUE;
        
    header('Location: index3.php?id='.$diverid.'');
        }else{
           
    $query "INSERT INTO diverlist(`diver_name`, `diver_password`,`diver_access`,`diver_online`,`diveremail`) VALUES( '".addslashes($_POST['username'])."','".addslashes($_POST['password'])."', '1','No','".addslashes($_POST['emailaccount'])."');
            
    $result = mysql_query($query);
        }
    }
    }
    function displayStatus(){
       
    $uname = $_SESSION['reguname'];
       if(
    $_SESSION['regresult']){
    ?>

    <h1>Registered!</h1>
    <p>Thank you........... <b><? echo 
    $uname; ?></b>, your information has been added to the database, you may now <a href="index.php" title="Login">log in</a>.</p>

    <?
       }
       else{
    ?>

    <h1>Registration Failed</h1>
    <p>We're sorry, but an error has occurred and your registration for the username <b><? echo 
    $uname; ?></b>, could not be completed.<br>
    Please try again at a later time.</p>

    <?
       }
       unset(
    $_SESSION['reguname']);
       unset(
    $_SESSION['registered']);
       unset(
    $_SESSION['regresult']);
    }

    if(isset(
    $_SESSION['registered'])){
    /**
     * This is the page that will be displayed after the
     * registration has been attempted.
     */
    ?>

    <html>
    <title>Registration Page</title>
    <body>

    <? displayStatus(); ?>

    </body>
    </html>

    <?php
       return;
    }

    if(isset(
    $_POST['subjoin'])){
       /* Make sure all fields were entered */
       if(!
    $_POST['user'] || !$_POST['pass']){
          die('You didn\'t fill in a required field.');
       }

       /* Spruce up username, check length */
       
    $_POST['user'] = trim($_POST['user']);
       if(strlen(
    $_POST['user']) > 30){
          die("
    Sorrythe username is longer than 30 charactersplease shorten it.");
       }

       /* Check if username is already in use */
       if(usernameTaken(
    $_POST['user'])){
          
    $use = $_POST['user'];
          die("
    Sorrythe username: <strong>$use</strongis already takenplease pick another one.");
       }

       /* Add the new account to the database */
       
    $md5pass = md5($_POST['pass']);
       
    $_SESSION['reguname'] = $_POST['user'];
       
    $_SESSION['regresult'] = addNewUser($_POST['user'], $md5pass);
       
    $_SESSION['registered'] = true;
       echo "
    <meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
       return;
    }
    else{

       
    include(
    "heading.html");   
    ?>

    <html>
    <title>Registration Page</title>
    <body>
    <h1>Register</h1>
    <form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
    <table align="left" border="0" cellspacing="0" cellpadding="3">
    <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr>
    <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr>
    <tr><td>Email :</td><td><input type="text" name="emailaccount" maxlength="50"></td></tr>
    <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr>
    </table>
    </form>
    </body>
    </html>

    <?
    }
    ?>
    Last edited by gohhs; Jul 12, 2007 at 07:47.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    missing ?

    Please edit your post by putting the code inside &#91;PHP] bbcode tags or the syntax select.

  3. #3
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    PHP Code:
    <?php
    session_start
    (); 
    include(
    "photoconfig.php"); 
    if(isset(
    $_POST['submit']))
    {
    if(!isset(
    $_POST['username']) || $_POST['username'] == '' || !isset($_POST['password']) || $_POST['password'] == ''|| !isset($_POST['emailaccount']) || $_POST['emailaccount'] == '')
    {
    header('Location: login.php?err=true'); 
    }else{
    $username $_POST['username'];
    $password $_POST['password'];
    $emailaccount $_POST['emailaccount'];
    $query "SELECT * FROM diverlist WHERE diver_name = '$username' AND diver_password = '$password'";
    $result mysql_query($query) or die("Register failed. " mysql_error());
    $numrows mysql_num_rows($result);
    if(
    $numrows !== 0){
    $info mysql_fetch_assoc($result);
    $diverid $info['diver_name'];
    $_SESSION[$diverid] = TRUE;
    $_SESSION['regresult'] = TRUE;
    header('Location: index3.php?id='.$diverid);
    }else{
    $query "INSERT INTO diverlist(`diver_name`, `diver_password`,`diver_access`,`diver_online`,`diveremail`) VALUES( 
    '"
    .addslashes($_POST['username'])."',
    '"
    .addslashes($_POST['password'])."', 
    '1',
    'No',
    '"
    .addslashes($_POST['emailaccount'])."'"
    );
    $result mysql_query($query);
    }
    }
    }
    function 
    displayStatus(){
    $uname $_SESSION['reguname'];
    if(
    $_SESSION['regresult']){
    ?>

    <h1>Registered!</h1>
    <p>Thank you........... <b><? echo $uname?></b>, your information has been added to the database, you may now <a href="index.php" title="Login">log in</a>.</p>

    <?
    }
    else{
    ?>

    <h1>Registration Failed</h1>
    <p>We're sorry, but an error has occurred and your registration for the username <b><? echo $uname?></b>, could not be completed.<br>
    Please try again at a later time.</p>

    <?
    }
    unset(
    $_SESSION['reguname']);
    unset(
    $_SESSION['registered']);
    unset(
    $_SESSION['regresult']);
    }

    if(isset(
    $_SESSION['registered'])){
    /**
    * This is the page that will be displayed after the
    * registration has been attempted.
    */
    ?>

    <html>
    <title>Registration Page</title>
    <body>

    <? displayStatus(); ?>

    </body>
    </html>

    <?php
    return;
    }

    if(isset(
    $_POST['subjoin'])){
    /* Make sure all fields were entered */
    if(!$_POST['user'] || !$_POST['pass']){
    die(
    'You didn\'t fill in a required field.');
    }

    /* Spruce up username, check length */
    $_POST['user'] = trim($_POST['user']);
    if(
    strlen($_POST['user']) > 30){
    die(
    "Sorry, the username is longer than 30 characters, please shorten it.");
    }

    /* Check if username is already in use */
    if(usernameTaken($_POST['user'])){
    $use $_POST['user'];
    die(
    "Sorry, the username: <strong>$use</strong> is already taken, please pick another one.");
    }

    /* Add the new account to the database */
    $md5pass md5($_POST['pass']);
    $_SESSION['reguname'] = $_POST['user'];
    $_SESSION['regresult'] = addNewUser($_POST['user'], $md5pass);
    $_SESSION['registered'] = true;
    echo 
    "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
    return;
    }
    else{


    include(
    "heading.html"); 
    ?>

    <html>
    <title>Registration Page</title>
    <body>
    <h1>Register</h1>
    <form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
    <table align="left" border="0" cellspacing="0" cellpadding="3">
    <tr><td>Username/td><td><input type="text" name="user" maxlength="30"></td></tr>
    <tr><td>Password/td><td><input type="password" name="pass" maxlength="30"></td></tr>
    <tr><td>Email /td><td><input type="text" name="emailaccount" maxlength="50"></td></tr>
    <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr>
    </table>
    </form>
    </body>
    </html>

    <?
    }
    ?>
    missed a closing " off the end of the query line
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeap, i got it.
    after changed and modify the code, I still cannot registered the data,
    no data have benn inserted into the database, how should i identify the problem ?

    following is my code, please tell me where is the problem, or suggest me how to trouble shoot the problem..

    PHP Code:
    <?php
    session_start
    (); 
    include(
    "photoconfig.php"); 
    if(isset(
    $_POST['subjoin']))
    {
       if(!
    $_POST['user'] || !$_POST['pass']){
          die(
    'You didn\'t fill in a required field.');
       }

       
    /* Spruce up username, check length */
       
    $_POST['user'] = trim($_POST['user']);
       if(
    strlen($_POST['user']) > 30){
          die(
    "Sorry, the username is longer than 30 characters, please shorten it.");
       }

      if(!isset(
    $_POST['username']) || $_POST['username'] == '' || !isset($_POST['password']) || $_POST['password'] == ''|| !isset($_POST['emailaccount']) || $_POST['emailaccount'] == '')
        {
        
    header('Location: register.php?err=true'); 
        }else{
        
    $username $_POST['username'];
        
    $password $_POST['password'];
        
    $emailaccount $_POST['emailaccount'];
        
    $query "SELECT * FROM diverlist WHERE diver_name = '$username'";
        
    $result mysql_query($query) or die("Register failed. " mysql_error());
        
    $numrows mysql_num_rows($result);
        if(
    $numrows !== 0){
        
    $info mysql_fetch_assoc($result);
        
    $diverid $info['diver_name'];
         die(
    "Sorry, the username: <strong>$diverid</strong> is already taken, please pick another one.");
        }else{
           
    $query "INSERT INTO diverlist(`diver_name`, `diver_password`,`diver_access`,`diver_online`,`diveremail`) VALUES( '".addslashes($_POST['username'])."','".addslashes($_POST['password'])."', '1','No','".addslashes($_POST['emailaccount'])."')";
            
    $result mysql_query($query);
            
    $_SESSION[''.$diverid.''] = TRUE;
            
    $_SESSION['regresult'] = TRUE;
            
    $_SESSION['reguname'] = $_POST['diver_name'];
            
    $_SESSION['registered'] = true;
            
    header('Location: index3.php?id='.$diverid.'');
        }
    }
    }
    function 
    displayStatus(){
       
    $uname $_SESSION['reguname'];
       if(
    $_SESSION['regresult']){
    ?>

    <h1>Registered!</h1>
    <p>Thank you........... <b><? echo $uname?></b>, your information has been added to the database, you may now <a href="index.php" title="Login">log in</a>.</p>

    <?
       
    }
       else{
    ?>

    <h1>Registration Failed</h1>
    <p>We're sorry, but an error has occurred and your registration for the username <b><? echo $uname?></b>, could not be completed.<br>
    Please try again at a later time.</p>

    <?
       
    }
       unset(
    $_SESSION['reguname']);
       unset(
    $_SESSION['registered']);
       unset(
    $_SESSION['regresult']);
    }

    if(isset(
    $_SESSION['registered'])){
    /**
     * This is the page that will be displayed after the
     * registration has been attempted.
     */
    ?>

    <html>
    <title>Registration Page</title>
    <body>

    <? displayStatus(); ?>

    </body>
    </html>

    <?php
       
    return;
    }

    if(isset(
    $_POST['subjoin'])){
       echo 
    "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
       return;
    }
    else{

       
    include(
    "heading.html");   
    ?>

    <html>
    <title>Registration Page</title>
    <body>
    <h1>Register</h1>
    <form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
    <table align="left" border="0" cellspacing="0" cellpadding="3">
    <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr>
    <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr>
    <tr><td>Email :</td><td><input type="text" name="emailaccount" maxlength="50"></td></tr>
    <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr>
    </table>
    </form>
    </body>
    </html>

    <?
    }
    ?>
    Last edited by gohhs; Jul 12, 2007 at 07:45.

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok.. i made it now to put the php bbtag, sorry for ealier post...
    Last edited by gohhs; Jul 12, 2007 at 07:48.

  6. #6
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Write your insert query like this
    PHP Code:
    $query "INSERT INTO diverlist(diver_name, diver_password,diver_access,diver_online,diveremail) VALUES( '".addslashes($username)."','".addslashes($password)."', '1','No','".addslashes($emailaccount)."')"
    instead of

    PHP Code:
    $query "INSERT INTO diverlist(`diver_name`, `diver_password`,`diver_access`,`diver_online`,`diveremail`) VALUES( '".addslashes($_POST['username'])."','".addslashes($_POST['password'])."', '1','No','".addslashes($_POST['emailaccount'])."')"
    Barbara

  7. #7
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    982
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Every time you do a mysql_query, put it in a conditional. Example:
    PHP Code:
    $result mysql_query($query); 
    Would become:
    PHP Code:
    if ($result = @mysql_query($query)) {
    //success
    } else {
    //error 
    echo 'There was an error with the query: '.mysql_error();

    MySQL v5.1.58
    PHP v5.3.6


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •