Hello, I'm having bit trouble about this thing I made
I'm trying to redirect the page on 'changing the password' with the use of ACCT_CODE column from member table of alumni database but I can't seem to redirect it. can someone please help me and teach me where did I gone wrong with this?

P.S.
I've commented the line where I guess it started my problem up to the last line. (because whenever I add that important code to redirect to changepassword it always give me error

on this thing:
"Parse error: syntax error, unexpected T_ELSE in E:\xampp\htdocs\site\checklogin.php"

I'm using '0's and '1's to check if the user needs to change password(using the ACCT_CODE column), if that also helps to solve my problem.

Thanks for reading I hope you can help me with this

<?php session_start();

$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="3214"; // Mysql password 
$db_name="alumni"; // Database name 
$tbl_name="member"; // Table name

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

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$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

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
//-----------------
$_SESSION['current_username']=$myusername; 
//-----------------

//This is where the problem starts
$query="SELECT ACCT_CODE FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";


if($query==0){
{header("location: changepassword.php");}
else 
{header("location:login_success.php");}
}
//This is where the problem ends
else {
echo "Wrong Username or Password";
}
?>

Line 44 has an opening curly bracket too much.

You can avoid these errors easily, by indenting your code better.

I've already removed some curly brackets
I still won't work
and I've tried my $query to move above my first if statement but still no good

it still detect my 'ELSE' has a problem

if($query==0){
header("location: changepassword.php");

else 
header("location:login_success.php");
}
Member Avatar for diafol
if($query==0){
  header("location: changepassword.php");
  exit();
}else{ 
  header("location:login_success.php");
  exit();
}
//This is where the problem starts
$query="SELECT ACCT_CODE FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
 
 
if($query==0){
{header("location: changepassword.php");}
else 
{header("location:login_success.php");}
}
//This is where the problem ends
else {
echo "Wrong Username or Password";
}

First of all this part

$query="SELECT ACCT_CODE FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
 
 
if($query==0){
{header("location: changepassword.php");}
else 
{header("location:login_success.php");}
}

Your setting the query to something, which is a string, so this will never be 0, so this IF condition will never be meet.

Secondly

else {
echo "Wrong Username or Password";
}

This else statement is on its own, therefore it will cause a problem, IF Statements should be like the following;

if ( condition to test)
{
    //do something
}
else
{
    // do this if, the if condition is not passed;
}

// or an if statement can be like this

if ( condition to test)
{
    // do something
}
elseif ( another test condition )
{
    //do something if the above has not been passed;
}
else
{
    // do something if none of the above have been passed;
}

For more details on IF/ELSE controls check this manual page.


So for the tail part of your code it should be similar to the following;

if ( $count )
{

    // not really sure what your wanting to do, but you can have a column in the database called 'expiredPW' that has a 1 if the password is expired and a 0 if not for example;

    $query = "SELECT expiredPW FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";

    $result=mysql_query($query);

    if ( $result )
    {
        header("location:changepassword.php");
        exit();
    }
    else
    {
        header("location:login_success.php");
        exit();
    }
} 
else 
{
   // wrong details provided;
   header("location:login.php");
}

Hope this helps :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.