Parse error: syntax error, unexpected T_VARIABLE
I'm getting an error as i'm trying to create a login page which will allow users to be directed to the right page. e.g a student will be directed to the student page and the staff will be directed to the staff page but i don't know whats wrong with my code..help
<?php
ob_start();
$host="localhost"; // Host name
$username="amy"; // Mysql username
$password="annie"; // Mysql password
$db_name="pa"; // Database name
$tbl_name="user"; // Table name
// Get info from the session
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword and $myusertype
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myusertype=$_POST['myusertype'];
//$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and //password='$mypassword'";
//$result=mysql_query($sql);
$sql=("SELECT user_type FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and user_type ='$myusertype'");
//$result2=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result2);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1 ){
Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
session_register("myusertype");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
//ob_end_flush();
?>
this is the error message
Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\capat\checklogin.php on line 34
11 Months Ago
Last Updated
dami06
Junior Poster in Training
91 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
line 34. I think thats a comment missing "//"
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 357
Skill Endorsements: 17
yes thats the problem. thank you but another problem im still having is dircting the student to the student page, the staff to the staff page and the admin to the admin page. Could someone please help me on the code with how to achieve that please..thank you
dami06
Junior Poster in Training
91 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
How do you differentiate whether a user is an admin or a staff member or a student ?
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 357
Skill Endorsements: 17
I have different pages already for them and i put on my main login form for them to type in if they are a staff, student or admin.
This is my main_login.php and login_success.php
<BODY BGCOLOR="Teal">
<table width="900" border="20" align="center" cellpadding="3" cellspacing="6" bgcolor="BLACK">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="30" cellspacing="5" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="10">Username</td>
<td width="10">:</td>
<td width="600"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
<tr>
<td width="10">Usertype</td>
<td width="10">:</td>
<td width="600"><input name="myusertype" type="text" id="myusertype"></td>
</tr>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</BODY>
</table>
</td>
</form>
</tr>
</table>
login_success.php
<?
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
session_start();
if(!session_is_registered(myusername)){
header("location:http://www.yahoo.com");
}
else {
header("location:admin/index.php");
}
?>
<html>
<body>
Login Successful
</body>
</html>
dami06
Junior Poster in Training
91 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Well, then depending upon the input of the user, you can redirect him to relative page. According to you, the user enters the usertype in the textbox myusertype. When the user submits the page, get the value of myusertype.
$usertype=$_POST['myusertype'];
if($usertype=="student"){
//redirect to student page
} else if ($usertype=="admin") {
//redirect to admin page
} else if($usertype=="staff"){
//redirect to staff page
} else { // none of these 3 users
//redirect to error page
}
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 357
Skill Endorsements: 17
OK, so do i put this in my login_sucess.php page or my checklogin.php page and what line should i put it in
dami06
Junior Poster in Training
91 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Where are you validating the login ? When the user enters his username and password, where are you checking if he's a valid user ?
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 357
Skill Endorsements: 17
dami06
Junior Poster in Training
91 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
No dude! when the user enters the username and password, how will you know if he's a valid user and not a dummy one ?
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 357
Skill Endorsements: 17
Because, i have in put the user type, username and password in my database already. So because this is just something that will work on my laptop i only have about 6 users. 2 students, 2 staffs and 2 admin. Is that what you are asking for?
dami06
Junior Poster in Training
91 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
:) umm.. No.. Can you post the code of check_login.php ?
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 357
Skill Endorsements: 17
ok
checklogin.php
<?php
ob_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="pa"; // Database name
$tbl_name="user"; // Table name
// Get info from the session
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword and $myusertype
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myusertype=$_POST['myusertype'];
//$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and //password='$mypassword'";
//$result=mysql_query($sql);
$sql=("SELECT user_type FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and user_type ='$myusertype'");
//$result2=mysql_query($sql);
// Mysql_num_row is counting table row
//$count=mysql_num_rows($result2);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1 ){
//Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
session_register("myusertype");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
//ob_end_flush();
?>
dami06
Junior Poster in Training
91 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
You don't need a login_success.php page. Instead of redirecting to login_success.php page, redirect directly to admin/student/staff page ! This would be your new checklogin.php
<?php
ob_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="pa"; // Database name
$tbl_name="user"; // Table name
// Get info from the session
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword and $myusertype
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myusertype=$_POST['myusertype'];
//$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and //password='$mypassword'";
//$result=mysql_query($sql);
$sql=("SELECT user_type FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and user_type ='$myusertype'");
//$result2=mysql_query($sql);
// Mysql_num_row is counting table row
//$count=mysql_num_rows($result2);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1 ) {
//Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
session_register("myusertype");
if($myusertype=="admin") {
header("location: admin/index.php");
} else if($myusertype=="staff"){
header("location: staff/index.php");
} else if($myusertype=="student"){
header("location: student/index.php");
} else {
echo "Wrong usertype";
exit;
}
}
else {
echo "Wrong Username or Password";
}
//ob_end_flush();
?>
Try this.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 357
Skill Endorsements: 17
i have tried that but now it is just giving me wrong username and password for everything
dami06
Junior Poster in Training
91 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Well, You have so many "important" lines commented ! wait.. I ll edit my previous post. And I don't think it was working earlier.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 357
Skill Endorsements: 17
dami06
Junior Poster in Training
91 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
<?php
ob_start();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="pa"; // Database name
$tbl_name="user"; // Table name
// Get info from the session
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword and $myusertype
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myusertype=$_POST['myusertype'];
//$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and //password='$mypassword'";
//$result=mysql_query($sql);
$sql=("SELECT user_type FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and user_type ='$myusertype'");
$result2=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result2);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1 ) {
//Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
session_register("myusertype");
if($myusertype=="admin") {
header("location: admin/index.php");
} else if($myusertype=="staff"){
header("location: staff/index.php");
} else if($myusertype=="student"){
header("location: student/index.php");
} else {
echo "Wrong usertype";
exit;
}
}
else {
echo "Wrong Username or Password";
}
//ob_end_flush();
?>
If this doesn't work, I dont think I can help you with this.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 357
Skill Endorsements: 17
awww, you are a star nav..YOU ARE A GENIUS NAV..THANK YOUUUUUUUUUUUU
dami06
Junior Poster in Training
91 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 5 Years Ago by
nav33n nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 357
Skill Endorsements: 17