Jump to content

Recommended Posts

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");
       }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/98500-parse-error-syntax-error-unexpected/
Share on other sites

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>

 

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
}

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");
       }

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>

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.