0
<?php     //start php tag
//include connect.php page for database connection
Include('dbConnection.php');
//if submit is not blanked i.e. it is clicked.
// var_dump($_REQUEST);
session_start();

$errCount = 0;
$user = $_POST['usernameTbx'];
$pass = $_POST['passwordTbx'];
if(isset($_REQUEST['submit'])!='')
{
    //VALIDATE USERNAME TEXTBOX
    if($_REQUEST['usernameTbx']=='') {
        $errCount += 1;
        $_SESSION['error'] += array('usernameTbx' => "Username cannot be empty");

    }
    //VALIDATE PASSWORD TEXTBOX
    if($_REQUEST['passwordTbx']=='') {
        $errCount += 1;
        $_SESSION['error'] += array('passwordTbx' => "Password cannot be empty");
    } 

    if($errCount == 0) {
        $sql=mysql_query("Select username, password FROM user_tbl WHERE username = $user AND password = $pass");

        $row = mysql_fetch_array($sql);
        if($row["username"]==$user && $row["password"]==$pass)
        {
            $_SESSION['sysMsg'] = array('$strSuccess' => "You have successfully logged in!" );

        }
        else
        {
            $_SESSION['sysMsg'] = array('$strFail' => "Incorrect Username or Password" );
        }
    }
    header('Location: loginPage.php');
}

?>

This code always throws $strFail @_@. Can somebody tell me why? Thank you in advance.

3
Contributors
4
Replies
14
Views
3 Years
Discussion Span
Last Post by Ketul_1
1

Try this, if there's an error, paste it here.

$sql = mysql_query("Select username, password FROM user_tbl WHERE username = '$user' AND password = '$pass'") or die(mysql_error());
Votes + Comments
die(mysql_error()) helped me
0

it says there was a problem on where clause so i change my sql code to this:

$sql=mysql_query("Select username, password FROM user_tbl WHERE username = '".$_REQUEST['usernameTbx']."' AND password = '".$_REQUEST['passwordTbx']."'") or die(mysql_error());
0

I don't know what happen but it's already working. Thanks a lot!

<?php     //start php tag
//include connect.php page for database connection
Include('dbConnection.php');
//if submit is not blanked i.e. it is clicked.
// var_dump($_REQUEST);
session_start();
$user = $_POST['usernameTbx'];
$pass = $_POST['passwordTbx'];
$errCount = 0;

if(isset($_REQUEST['submit'])!='')
{
    //VALIDATE USERNAME TEXTBOX
    if($_REQUEST['usernameTbx']=='') {
        $errCount += 1;
        $_SESSION['error'] += array('usernameTbx' => "Username cannot be empty");

    }
    //VALIDATE PASSWORD TEXTBOX
    if($_REQUEST['passwordTbx']=='') {
        $errCount += 1;
        $_SESSION['error'] += array('passwordTbx' => "Password cannot be empty");
    } 

    if($errCount == 0) {
        // $sql=mysql_query("Select username, password FROM user_tbl WHERE username = '".$_REQUEST['usernameTbx']."' AND password = '".$_REQUEST['passwordTbx']."'") or die(mysql_error());
        $sql = mysql_query("Select username, password FROM user_tbl WHERE username = '$user' AND password = '$pass'") or die(mysql_error());

        $row = mysql_fetch_array($sql);
        if($row["username"]==$user && $row["password"]==$pass)
        {
            $_SESSION['sysMsg'] = array('$strSuccess' => "You have successfully logged in!" );

        }
        elseif($row["username"]!=$user && $row["password"]!=$pass)
        {
            $_SESSION['sysMsg'] = array('$strFail' => "Incorrect Username or Password" );
        }
    }
    header('Location: loginPage.php');
}

?>
0

Try This

<?php     //start php tag
//include connect.php page for database connection
Include('dbConnection.php');
//if submit is not blanked i.e. it is clicked.
// var_dump($_REQUEST);
session_start();
$errCount = 0;
$user = $_POST['usernameTbx'];
$pass = $_POST['passwordTbx'];
if(isset($_REQUEST['submit'])!='')
{
    //VALIDATE USERNAME TEXTBOX
    if($_REQUEST['usernameTbx']=='') {
        $errCount += 1;
        $_SESSION['error'] += array('usernameTbx' => "Username cannot be empty");
    }
    //VALIDATE PASSWORD TEXTBOX
    if($_REQUEST['passwordTbx']=='') {
        $errCount += 1;
        $_SESSION['error'] += array('passwordTbx' => "Password cannot be empty");
    } 

        $sql=mysql_query("Select username , password FROM user_tbl WHERE username ='".$user."' AND password = '".$pass."'");
        $row = mysql_fetch_array($sql); 
        if($row["username"]==$user && $row["password"]==$pass)
        {
            $_SESSION['sysMsg'] = array('$strSuccess' => "You have successfully logged in!" );
        }
        else
        {
            $_SESSION['sysMsg'] = array('$strFail' => "Incorrect Username or Password" );
        }

    header('Location: loginPage.php');
}
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.