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
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
Share on other sites

I could make it way simpler for you. But I truly don't think you want my login.. My connect is much different so it's hard to read what you're doing. You truly don't need to num_row.. I don't know how to explain how to fix it up without giving you the whole script.

Link to comment
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
Share on other sites

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.