1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Error in T_STRING in PHP code

Discussion in 'PHP' started by achraf52, Aug 3, 2011.

  1. #1
    Hi, my PHP code is designed to signin the user but it gives this error :

    Parse error: syntax error, unexpected T_STRING in E:\EasyPHP-5.3.6.1\www\signinok.php on line 56

    The code is :

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">   <html xmlns="http://www.w3.org/1999/xhtml">   <head>  <?php include('files/head.php'); ?>  </head>  <?php include('files/body.php'); ?>  <?php include('files/users.php'); ?>  </font></div>  <div ><div id="329164896891400782" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml">  <?php  $username = $_POST['username']; $password = $_POST['password'];  include('files/config.php";  if ($username==NULL)  {  echo "Put your username in form .";  }  else  if ($password==NULL)  {  echo "Put your password in form .";  }  else  {  include('config.php');  $checkuseraccount = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error()); while ($accountcheckingresult = mysql_fetch_array($checkuseraccount));  $dbusername = $accountcheckingresult["username"];  if ($dbusername != $username)  {  echo "You entered a wrong username .";  }  $dbpassword = $accountcheckingresult["password"];   if ($dbpassword != $password)  {  echo "You entered a wrong password .";  }  else  {  $cookieusername=$row['username']; $cookiepassword=$row['password'];  setcookie("username",$cookieusername,time()+31536000); setcookie("password",$cookiepassword,time()+31536000);  echo "You have been logged in .";  }  ?>  <?php include('files/foot.php'); ?>
    PHP:
     

    So please help me correcting .
     
    Last edited: Aug 3, 2011
    achraf52, Aug 3, 2011 IP
  2. The Webby

    The Webby Peon

    Messages:
    1,852
    Likes Received:
    30
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Horrible code..
    And its hardly 14 lines, with just a bunch of php includes.. The error must be in one of these included files.
    My wildest guess would be that you forgot to terminate a line with a semi-colon ( ; )
     
    The Webby, Aug 3, 2011 IP
  3. achraf52

    achraf52 Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The includes are all correct, the processing code is where there is a problem and there is more then 60 lines just they aren't shown correctly here, the code is not that, and I will update again .
     
    achraf52, Aug 3, 2011 IP
  4. The Webby

    The Webby Peon

    Messages:
    1,852
    Likes Received:
    30
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Few Errors in the code you have provided..


    Still there are no line 56.. It's only 38 lines long.
     
    The Webby, Aug 4, 2011 IP
  5. achraf52

    achraf52 Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The code looks like that on the file :

     
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    
    <?php include('files/head.php'); ?>
    
    </head>
    
    <?php
    include('files/body.php');
    ?>
    
    <?php
    include('files/users.php');
    ?>
    
    </font></div>  <div > <div id="329164896891400782" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml">
    
    <?php
    
    $username = $_POST['username'];
    $password = $_POST['password'];
    
    include('files/config.php";
    
    if ($username==NULL)
    
    {
    
    echo "Put your username in form .";
    
    }
    
    else
    
    if ($password==NULL)
    
    {
    
    echo "Put your password in form .";
    
    }
    
    else
    
    {
    
    include('files/config.php');
    
    $checkuseraccount = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error());
    
    while ($accountcheckingresult = mysql_fetch_array($checkuseraccount));
    
    $dbusername = $accountcheckingresult["username"];
    
    if ($dbusername != $username)
    
    {
    
    echo "You entered a wrong username .";
    
    }
    
    $dbpassword = $accountcheckingresult["password"];
    
    if ($dbpassword != $password)
    
    {
    
    echo "You entered a wrong password .";
    
    }
    
    else
    
    {
    
    $cookieusername=$row['username'];
    $cookiepassword=$row['password'];
    
    setcookie("username",$cookieusername,time()+31536000); 
    setcookie("password",$cookiepassword,time()+31536000);
    
    echo "You have been logged in .";
    
    }
    
    ?>
    
    <?php include('files/foot.php'); ?>
    
    
    PHP:
    So please check the 56 th line and let me know any error :

    Error is :

    Parse error: syntax error, unexpected T_STRING in E:\EasyPHP-5.3.6.1\www\signinok.php on line 56

    Waiting for help . 
     
    achraf52, Aug 4, 2011 IP
  6. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #6
    in notepad press ctrl+g and put 56 and tell what line has error

    Regards

    Alex
     
    kmap, Aug 4, 2011 IP
  7. The Webby

    The Webby Peon

    Messages:
    1,852
    Likes Received:
    30
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Line 54, That's the cause of error -
    
    54 while ($accountcheckingresult = mysql_fetch_array($checkuseraccount));
    55
    56 $dbusername = $accountcheckingresult["username"];
    
    PHP:
    while ($accountcheckingresult = mysql_fetch_array($checkuseraccount)); // Its a loop, it should be followed by { not ;

    Like this:
    
    while ($accountcheckingresult = mysql_fetch_array($checkuseraccount)){
         // code in the while loop here
    } // End While
    
    PHP:
     
    Last edited: Aug 4, 2011
    The Webby, Aug 4, 2011 IP
  8. achraf52

    achraf52 Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hi,

    Here is it :

     
    
    
    54 : $checkuseraccount = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error());
    55 : while ($accountcheckingresult = mysql_fetch_array($checkuseraccount));
    56 : 
    57 :  $dbusername = $accountcheckingresult["username"];
    
    
    PHP:
    Hope it helps .
     
    achraf52, Aug 4, 2011 IP
  9. The Webby

    The Webby Peon

    Messages:
    1,852
    Likes Received:
    30
    Best Answers:
    1
    Trophy Points:
    0
    #9
    I already told you what is the error, and gave you the solution -

     
    The Webby, Aug 4, 2011 IP
  10. achraf52

    achraf52 Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Hi, now I did it but always it gives the same error :

    
    
    54 : $checkuseraccount = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error());
    55 : while ($accountcheckingresult = mysql_fetch_array($checkuseraccount))
    56 : 
    57 : {
    58 :
    59 : $dbusername = $accountcheckingresult["username"];
    60 :
    61 : $dbpassword = $accountcheckingresult["password"];
    62 :
    63 : }
    
    
    PHP:
     

    Error :

    Parse error: syntax error, unexpected T_STRING in E:\EasyPHP-5.3.6.1\www\signinok.php on line 56

    So what about this crazy line . 
     
    achraf52, Aug 4, 2011 IP
  11. The Webby

    The Webby Peon

    Messages:
    1,852
    Likes Received:
    30
    Best Answers:
    1
    Trophy Points:
    0
    #11
    Attach the signinok.php in your post.. So I can take a look.
     
    The Webby, Aug 4, 2011 IP
  12. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #12
    include('files/config.php";
    Code (markup):
    did you fix this?


    include('files/config.php');
    Code (markup):
     
    exodus, Aug 4, 2011 IP
  13. The Webby

    The Webby Peon

    Messages:
    1,852
    Likes Received:
    30
    Best Answers:
    1
    Trophy Points:
    0
    #13
    But of course, Thanks for pointing that out exodus..

    I don't think you fixed any of the errors I point out in the earlier post? Take a look again and pay attention to bold and Red part, they are errors in your code:

     
    The Webby, Aug 4, 2011 IP
  14. achraf52

    achraf52 Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Hi, now the problems are solved thanks to The Webby and Exodus but a small new problem happened, when I enter a wrong username and a password it shows :

    Notice: Undefined variable: dbusername in E:\EasyPHP-5.3.6.1\www\signinok.php on line 73
    You entered a wrong username .

    But when I enter username and wront password it works good, so how to skip the error shown .

    Code is :

     
    
    
    if ($dbusername != $username)
    
    {
    
    echo "You entered a wrong username .";
    
    exit();
    
    }
    
    if ($dbpassword != $password)
    
    {
    
    echo "You entered a wrong password .";
    
    exit();
    
    }
    
    
    PHP:
     
    achraf52, Aug 4, 2011 IP
  15. The Webby

    The Webby Peon

    Messages:
    1,852
    Likes Received:
    30
    Best Answers:
    1
    Trophy Points:
    0
    #15
    This should solve that problem
    
    if ((isset($dbusername)) && ($dbusername != $username))
    {
    
    echo "You entered a wrong username .";
    
    exit();
    
    }
    if ((isset($dbpassword)) && ($dbpassword != $password))
    
    {
    
    echo "You entered a wrong password .";
    
    exit();
    
    }
    
    PHP:
     
    The Webby, Aug 4, 2011 IP
  16. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #16
    if (!empty($dbusername)) {
    if ($dbusername != $username)
    
    {
    
    echo "You entered a wrong username .";
    
    exit();
    
    }
    
    if ($dbpassword != $password)
    
    {
    
    echo "You entered a wrong password .";
    
    exit();
    
    }
    } else {
            die('Hey turd, go back and fill in your username!');
    }
    PHP:
    Basic coding skills is needed. Let me guess your self taught coder? You have to make sure the var is set before you can use it. Your not setting the dbusername var before you are using it. You might have some code that sets it if the user is in the db, but you don't have anything that will set it if it is not in the db.
     
    Last edited: Aug 4, 2011
    exodus, Aug 4, 2011 IP
  17. achraf52

    achraf52 Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    If $dbusername or $dbpassword is not set (empty) the code in the top will stop the process and say "Put your password in form" just when it is not correct . 
     
    achraf52, Aug 4, 2011 IP
  18. achraf52

    achraf52 Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #18
     Now I've used your code but instead of the old error it shows :

    Notice: Undefined variable: dbusername in E:\EasyPHP-5.3.6.1\www\signinok.php on line 99
    Notice: Undefined variable: dbpassword in E:\EasyPHP-5.3.6.1\www\signinok.php on line 100
    You have been logged in .

    When I enter wrong username and any password . 
     
    achraf52, Aug 4, 2011 IP
  19. achraf52

    achraf52 Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    Here how to the code looks now :

    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">   <html xmlns="http://www.w3.org/1999/xhtml">   <head>  <?php include('files/head.php'); ?>  </head>  <?php include('files/body.php'); ?>  <?php include('files/users.php'); ?>  </font></div>  <div ><div id="329164896891400782" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml">  <?php  $username = $_POST['username']; $password = $_POST['password'];  include('files/config.php');  if ($username==NULL)  {  echo "Put your username in form .";  exit();  }  else  if ($password==NULL)  {  echo "Put your password in form .";  exit();  }  else  {  include('files/config.php');  $checkuseraccount = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error()); while ($accountcheckingresult = mysql_fetch_array($checkuseraccount))  {  $dbusername = $accountcheckingresult["username"];  $dbpassword = $accountcheckingresult["password"];  }  if ((isset($dbusername)) && ($dbusername != $username))  {  echo "You entered a wrong username .";  exit();  }  else  if ((isset($dbpassword)) && ($dbpassword != $password))  {  echo "You entered a wrong password .";  exit();  }  else  {  $cookieusername=$dbusername; $cookiepassword=$dbpassword;  setcookie("username",$cookieusername,time()+31536000); setcookie("password",$cookiepassword,time()+31536000);  echo "You have been logged in .";  }  }  ?>  <?php include('files/foot.php'); ?>
    
    
    PHP:
    And the error is that when I enter a wrong username according to on database and any password, it shows nothing . 
     
    achraf52, Aug 4, 2011 IP
  20. The Webby

    The Webby Peon

    Messages:
    1,852
    Likes Received:
    30
    Best Answers:
    1
    Trophy Points:
    0
    #20
    Take the clue mate, You need to check if the variable is set before you try to use it.
    use isset() to check if the var is set or not..
     
    The Webby, Aug 4, 2011 IP