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