mikebyrne Posted March 29, 2008 Share Posted March 29, 2008 Im getting the error Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\Main Page\login.php on line 303 line 303 is: else if ($_SESSION['usertype'] == "1" && logged = 'true') my php so far <?php session_start(); include("adminconnect.php"); $tbl_name="adminusers"; if(isset($_POST['uname']) && isset($_POST['pword'])) { // Define $myusername and $mypassword $uname=mysql_escape_string($_POST['uname']); $pword=mysql_escape_string($_POST['pword']); $sql="SELECT * FROM $tbl_name WHERE username='$uname' and password='$pword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row /* grab the usertype */ $r = mysql_fetch_array($result); /* We will verify that the num_rows exists, for some reason you weren'y verifying this */ /* After verifying, we will then set the session, this is assuming that there is a column */ /* in your table named 'type' and its value is either '1' or '2' */ if ($count > 0) { $_SESSION['type'] = $r['usertype']; $logged = true; } else { echo "Wrong Username/Password."; } if ($_SESSION['usertype'] == "2" && $logged = 'true') { header("Location: ../Admin_files/start.php"); } else if ($_SESSION['usertype'] == "1" && logged = 'true') { header("Location: ../Main Page/first.php"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/98500-parse-error-syntax-error-unexpected/ Share on other sites More sharing options...
maexus Posted March 29, 2008 Share Posted March 29, 2008 else if ($_SESSION['usertype'] == "1" && logged == 'true') Quote Link to comment https://forums.phpfreaks.com/topic/98500-parse-error-syntax-error-unexpected/#findComment-504081 Share on other sites More sharing options...
mikebyrne Posted March 29, 2008 Author Share Posted March 29, 2008 My form just seems to refresh itself as opposed to redirecting to the correct page <?php session_start(); include("adminconnect.php"); $tbl_name="adminusers"; if(isset($_POST['uname']) && isset($_POST['pword'])) { // Define $myusername and $mypassword $uname=mysql_escape_string($_POST['uname']); $pword=mysql_escape_string($_POST['pword']); $sql="SELECT * FROM $tbl_name WHERE username='$uname' and password='$pword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row /* grab the usertype */ $r = mysql_fetch_array($result); /* We will verify that the num_rows exists, for some reason you weren'y verifying this */ /* After verifying, we will then set the session, this is assuming that there is a column */ /* in your table named 'type' and its value is either '1' or '2' */ if ($count > 0) { $_SESSION['type'] = $r['usertype']; $logged = true; } else { echo "Wrong Username/Pad =ssword."; } if ($_SESSION['usertype'] == "2" && $logged == 'true') { header("Location: ../Admin_files/start.php"); } else if ($_SESSION['usertype'] == "1" && logged == 'true') { header("Location: ../Main Page/first.php"); } } ?> <form action="login.php" method="POST"> <div align="right">Pleas enter your Login Name</b> <BR>(This is the name you signed up with)</div> </td> <td width="50%"> <input type="text" name="uname" size="12" maxlength="50" class="field"> </td> </tr> <tr> <td class="bgrl"> <div align="right">Please enter your <b>password</b></div> </td> <td width="50%" class="bgrl"> <input type="password" name="pword" size="18" class="field"> </td> </tr> <tr><td> </td> <td> <input type="submit" value="Login »" class="submit"></form></td> </tr> <tr><td colspan="2" class="genericside"><span class="t11bw">Forgotten your password?</span></td> </tr> <tr valign="top"> <td class="alignright"> <form name="passwordreminder" action="/member_login.php" method="post"> <input type="hidden" name="type" value="passwordreminder"> Please enter your email here:</td> <td><input type="text" name="reminderemail" class="field" maxlength="50"><br> <input type="submit" value="Send Password »" class="submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/98500-parse-error-syntax-error-unexpected/#findComment-504139 Share on other sites More sharing options...
Cep Posted March 29, 2008 Share Posted March 29, 2008 Shouldn't it be <?php else if (($_SESSION['usertype'] == "1") && ($logged == "true")) ?> However as your evaluating true for your $logged var you don't need quotes if its a bool type. Quote Link to comment https://forums.phpfreaks.com/topic/98500-parse-error-syntax-error-unexpected/#findComment-504148 Share on other sites More sharing options...
BlueSkyIS Posted March 29, 2008 Share Posted March 29, 2008 in fact, quotes may produce unexpected results. true is not equal to 'true'. additionally, a lot of things ARE equal to true, so when checking a boolean it is best to use 3 equals signs: if ($bool_val === true) { // $bool_val is equal to and is the same type as true } Quote Link to comment https://forums.phpfreaks.com/topic/98500-parse-error-syntax-error-unexpected/#findComment-504151 Share on other sites More sharing options...
sasa Posted March 29, 2008 Share Posted March 29, 2008 try if ($_SESSION['usertype'] == "2" && $logged == true) //remove '' { header("Location: ../Admin_files/start.php"); } else if ($_SESSION['usertype'] == "1" && $logged == true) // ad $ and remove '' { header("Location: ../Main Page/first.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/98500-parse-error-syntax-error-unexpected/#findComment-504159 Share on other sites More sharing options...
BlueSkyIS Posted March 29, 2008 Share Posted March 29, 2008 (best to use $logged === true) Quote Link to comment https://forums.phpfreaks.com/topic/98500-parse-error-syntax-error-unexpected/#findComment-504162 Share on other sites More sharing options...
mikebyrne Posted March 29, 2008 Author Share Posted March 29, 2008 My code still doesnt redirect to the pages but only to itself!!! for example my tables look like this CREATE TABLE `adminusers` ( `name` varchar(255) collate latin1_general_ci default NULL, `address` varchar(255) collate latin1_general_ci default NULL, `address1` varchar(255) collate latin1_general_ci default NULL, `address2` varchar(255) collate latin1_general_ci default NULL, `address3` varchar(255) collate latin1_general_ci default NULL, `address4` varchar(255) collate latin1_general_ci default NULL, `county` varchar(255) collate latin1_general_ci default NULL, `zip` varchar(255) collate latin1_general_ci default NULL, `telephone` decimal(10,0) default NULL, `email` varchar(255) collate latin1_general_ci default NULL, `username` varchar(255) collate latin1_general_ci default NULL, `password` varchar(255) collate latin1_general_ci default NULL, `usertype` decimal(10,0) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; -- ---------------------------- -- Records -- ---------------------------- INSERT INTO `adminusers` VALUES ('', '23 Ashville', 'Athy', 'Co Kildare', 'Ashville', 'Ashville', 'Kildae', '900210', '9999999999', 'yrne000@hotmail.com', 'Mikebyrne000', 'gerrard000', '2'); INSERT INTO `adminusers` VALUES ('Me', 'xxx', 'xxx', 'xxx', 'xxx', 'xxx', 'xxx', 'xxx', '777777', 'ghghhg', 'user', 'user', '1'); I login with user user and expect the page First.php to come up My code is <?php session_start(); include("adminconnect.php"); $tbl_name="adminusers"; if(isset($_POST['uname']) && isset($_POST['pword'])) { // Define $myusername and $mypassword $uname=mysql_escape_string($_POST['uname']); $pword=mysql_escape_string($_POST['pword']); $sql="SELECT * FROM $tbl_name WHERE username='$uname' and password='$pword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row /* grab the usertype */ $r = mysql_fetch_array($result); /* We will verify that the num_rows exists, for some reason you weren'y verifying this */ /* After verifying, we will then set the session, this is assuming that there is a column */ /* in your table named 'type' and its value is either '1' or '2' */ if ($count > 0) { $_SESSION['type'] = $r['usertype']; $logged = true; } else { echo "Wrong Username/Pad =ssword."; } if ($_SESSION['usertype'] === "2" && $logged == true) //remove '' { header("Location: ../Admin_files/start.php"); } else if ($_SESSION['usertype'] === "1" && $logged == true) // ad $ and remove '' { header("Location: ../Main Page/first.php"); } } ?> <form action="login.php" method="POST"> <div align="right">Pleas enter your Login Name</b> <BR>(This is the name you signed up with)</div> </td> <td width="50%"> <input type="text" name="uname" size="12" maxlength="50" class="field"> </td> </tr> <tr> <td class="bgrl"> <div align="right">Please enter your <b>password</b></div> </td> <td width="50%" class="bgrl"> <input type="password" name="pword" size="18" class="field"> </td> </tr> <tr><td> </td> <td> <input type="submit" value="Login »" class="submit"></form></td> </tr> <tr><td colspan="2" class="genericside"><span class="t11bw">Forgotten your password?</span></td> </tr> <tr valign="top"> <td class="alignright"> <form name="passwordreminder" action="/member_login.php" method="post"> <input type="hidden" name="type" value="passwordreminder"> Please enter your email here:</td> <td><input type="text" name="reminderemail" class="field" maxlength="50"><br> <input type="submit" value="Send Password »" class="submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/98500-parse-error-syntax-error-unexpected/#findComment-504186 Share on other sites More sharing options...
sasa Posted March 29, 2008 Share Posted March 29, 2008 you set $_SESSION['type'] and compare with $_SESSION['usertype'] Quote Link to comment https://forums.phpfreaks.com/topic/98500-parse-error-syntax-error-unexpected/#findComment-504201 Share on other sites More sharing options...
mikebyrne Posted March 29, 2008 Author Share Posted March 29, 2008 you set $_SESSION['type'] and compare with $_SESSION['usertype'] Sorry Sasa, What do you mean? Im a session noob as you can tell! Quote Link to comment https://forums.phpfreaks.com/topic/98500-parse-error-syntax-error-unexpected/#findComment-504234 Share on other sites More sharing options...
Cep Posted March 30, 2008 Share Posted March 30, 2008 He means you have set a value in one session called 'type' and then as part of a condition somewhere in your code you have tested against a session called 'usertype'. Basically you put something in a red car and then stopped a blue car to find it. Quote Link to comment https://forums.phpfreaks.com/topic/98500-parse-error-syntax-error-unexpected/#findComment-504426 Share on other sites More sharing options...
mikebyrne Posted March 30, 2008 Author Share Posted March 30, 2008 So $_SESSION['type'] = $r['usertype']; should be $_SESSION['usertype'] = $r['usertype']; ??? Quote Link to comment https://forums.phpfreaks.com/topic/98500-parse-error-syntax-error-unexpected/#findComment-504432 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.