Jump to content

My login doesn't work!


Xyphon

Recommended Posts

<?PHP

// Connects to your Database

include('Connect.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

$_POST['username'] = addslashes($_POST['username']);

$usercheck = $_POST['username'];

$_POST['password'] = addslashes($_POST['password']);

$passcheck = $_POST['password'];

$Result1= mysql_query("SELECT * FROM users WHERE username='$usercheck' AND password='$passcheck'");

$Rows1= mysql_fetch_array($Result1);

$Rows2= mysql_fetch_array($Result2);

 

 

if($Rows1==0)

{

echo "Invalid Username/password.";

exit;

}

 

$UserID= $Rows1['ID'];

 

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

 

echo "You have successfully logged in.<br /><br /><a href='index.php'>Continue</a>";

}

//If Form Isn't Submitted

else

{

echo "

<form method='POST'>

<input type='hidden' name='submit' value='1'>

 

<b>Username</b><br />

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

<br /><br />

<b>Password</b><br />

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

<br /><br />

<input type='submit' value='Sign In' onclick=\"this.disabled='true'; this.value='Please Wait...'; this.form.submit();\">

</form>";

}

 

?>

 

 

 

The error is no matter what I type in, even if it's valid, it says invalid user/password.

Link to comment
https://forums.phpfreaks.com/topic/81401-my-login-doesnt-work/
Share on other sites

<?php
// Connects to your Database
include ('Connect.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[/url] to go back.";

    //Exit Page
    exit;
}

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


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

    $UserID = $Rows1['ID'];

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

    echo "You have successfully logged in.

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

Username

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



Password

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



<input type='submit' value='Sign In' onclick=\"this.disabled='true'; this.value='Please Wait...'; this.form.submit();\">
</form>";
}

?>

 

mysql_num_rows

Link to comment
https://forums.phpfreaks.com/topic/81401-my-login-doesnt-work/#findComment-413104
Share on other sites

Thank you.. But now it says

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/ptcrpg.awardspace.com/login.php on line 28

Invalid Username/password.

 

I am a big noob, and I have trouble with errors. Do you know what else is wrong?

Link to comment
https://forums.phpfreaks.com/topic/81401-my-login-doesnt-work/#findComment-413107
Share on other sites

Thanks, but now theres soemthing wrong wiht my cookie

Warning: Cannot modify header information - headers already sent by (output started at /home/www/ptcrpg.awardspace.com/login.php:8) in /home/www/ptcrpg.awardspace.com/login.php on line 35

 

My friend had the same problem so he used sessions, but cookies are easier.

Link to comment
https://forums.phpfreaks.com/topic/81401-my-login-doesnt-work/#findComment-413132
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.