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 .
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 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 .
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 .Â
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:
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 .
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 .Â
include('files/config.php"; Code (markup): did you fix this? include('files/config.php'); Code (markup):
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:
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:
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:
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.
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 .Â
 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 .Â
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 .Â
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..