Jump to content

IF statement problem!


GateGuardian

Recommended Posts

<?php
//Includes
include 'Libary/opendb.php';

//Get user posted info
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection
$myusername = stripslashes($myusername);
$myusername = mysql_real_escape_string($myusername);

$sql="SELECT * FROM usersinfo WHERE Username='$myusername' AND Password='$mypassword'";
$result=mysql_query($sql) or die(mysql_error());

// Mysql_num_row is counting rows returned
$count=mysql_num_rows($result) or die(mysql_error());

// If result matched $myusername and $mypassword, table row must be 1 row
if ( $count==1 ) {
session_start();
session_register("myusername");
session_register("mypassword");
$_SESSION['Username']=$myusername;
header("location:members.php");
} else {
header("location:index.php");
}

?>

 

If i login with the right password, it starts the session and redirects me to members.php and everything works fine!

 

If i login with the wrong password, it just displays me a blank page!

 

ive even tried changing

 

} else {
header("location:index.php");
}

 

To..

 

} else {
echo "Wrong password!";
}

 

Yet i still get a blank page?

 

Anyone enlighten me why?

 

Link to comment
https://forums.phpfreaks.com/topic/111940-if-statement-problem/
Share on other sites

..try this if it doesnt work see what the result is from the num_rows

 

if ($count != 1)
{
     echo 'Bug Testing!';
}
else
{
     //everything else
}

 

Blank page again

 

I also change it just too

 

// Mysql_num_row is counting rows returned
$count=mysql_num_rows($result) or die(mysql_error());

echo $count;
// If result matched $myusername and $mypassword, table row must be 1 row
?>

 

Got blank page again ^^

Link to comment
https://forums.phpfreaks.com/topic/111940-if-statement-problem/#findComment-574547
Share on other sites

Rawr, got mixed up. I was getting confused forget my last 2 posts.

 

This is my login look through it to see what's wrong.

<?PHP
// Connects to your Database
include ('Connect.php');
include('top.php');
$submit = $_POST['submit'];

//Body Settings
echo "<center><font color='#AFAFAF' face='verdana' size='1'>";

//If User Is Logged In
if (isset($_COOKIE['UserID'])) {
    //Display Message
    echo "Sorry, you are already logged in. Click <a href='index.php'>Here</a> to go back.";

    //Exit Page
    exit;
}

//If Form Is Submitted
if ($submit) {
    // Checks if pass/user exists
    $usercheck = addslashes($_POST['username']);
    $passcheck = md5(addslashes($_POST['password']));
    $Result1 = mysql_query("SELECT * FROM users WHERE username='$usercheck' AND password='$passcheck'");
    $Rows1 = mysql_fetch_array($Result1);


    if (mysql_num_rows($Result1) == 0) {
        echo "Invalid Username/password.";
        exit;
    }

    $UserID = $Rows1['ID'];

$UserName = $Rows1['username'];

$UserPosition = $Rows1['UserPosition'];

    setcookie("UserID", "$UserID", time() + 9999999);
setcookie("UserPosition", "$UserPosition", time() + 9999999);
setcookie("UserName", "$UserName", time() + 9999999);

$User_IP = $_SERVER['REMOTE_ADDR'];

mysql_query ("UPDATE users SET user_ip='$User_IP' WHERE username='$usercheck'");
mysql_query ("UPDATE pokemon_info WHERE username='$usercheck'");
    echo "You have successfully logged in.

<a href='index.php'>Continue</a>";
}
//If Form Isn't Submitted
else {
    echo "
<form id='frm' method='POST'>
<input type='hidden' name='submit' value='1'>

<b>Username</b>

<input type=\"text\" name=\"username\" maxlength=\"30\">
<br />


<b>Password</b>

<input type=\"password\" name=\"password\" maxlength=\"25\">
<br />


<input type='submit' value='Sign In'>
</form>";
}
include('bottom.php');
?>

 

Link to comment
https://forums.phpfreaks.com/topic/111940-if-statement-problem/#findComment-574569
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.