Jump to content

Login page just refreshes.


batstanggt

Recommended Posts

Ive finally figured out the registration page.

However the login page does not want to co-operate...

for whatever reason it just keeps refreshing.

I have the html and the php separate so i will post both codes in the post and one immediately subsequent.

 

<form name="login" method="post" action="login.php">
<table border="0" width="225" align="center">
    <tr>
        <td width="219" bgcolor="#999999">
            <p align="center"><font color="white"><span style="font-size:12pt;"><b>Login</b></span></font></p>
        </td>
    </tr>
    <tr>
        <td width="219">
            <table border="0" width="220" align="center">
                <tr>
                    <td width="71"><span style="font-size:10pt;">Username:</span></td>
                    <td width="139"><input type="text" name="username"></td>
                </tr>
                <tr>
                    <td width="71"><span style="font-size:10pt;">Password:</span></td>
                    <td width="139"><input type="password" name="password"></td>
                </tr>
                <tr>
                    <td width="71"> </td>
                        <td width="139">
                            <p align="right"><input type="submit" name="submit" value="Submit"></p>
                        </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td width="219" bgcolor="#999999"><font color="white">Not Registered? </font><a href="register.html" target="_self"><font color="white">Register</font></a><font color="white"> </font><b><i><font color="white">Now!</font></i></b></td>
    </tr>
</table>
</form>

Link to comment
Share on other sites

  • Replies 65
  • Created
  • Last Reply

Top Posters In This Topic

And here is the .php file

<?php

//Database Information

$dbhost = "localhost";
$dbname = "dbname";
$dbuser = "mysqluname";
$dbpass = "mysqlpass";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

session_start();
$username = $_POST['username'];
$password = md5($_POST['password']);

$query = "select * from users where username='$username' and password='$password'";

$result = mysql_query($query);

if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
    include "login.html";

} else {
    $_SESSION['username'] = "$username";
    include "memberspage.php";
}

?>

Link to comment
Share on other sites

What do you mean it just keeps refreshing? If you mean it is always says bad login and includes the Login.html, try var_dump(mysql_num_rows($result)) and see what is the value of that, its the value that you are comparing to "1".

Link to comment
Share on other sites

When I say that it just refreshes, I mean that when in put a username and a password then enter. The browse screen just "flashes" and reloads the Login screen. Cant remember if its the /login.php or /login.html that is left in the address bar once it does its lil "refresh" thing.

Link to comment
Share on other sites

k so im back at it and i moved the session_start(); to the top just underneath the <?php.

here is the revised code. The problem does however persist. When you click Login on the login.html page the browser just loads the login.php page. However this just displays the login table.

<?php
session_start();
//Database Information

$dbhost = "localhost";
$dbname = "mygreensky";
$dbuser = "root";
$dbpass = "04mustanggt";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());


$username = $_POST['username'];
$password = md5($_POST['password']);

$query = "select * from users where username='$username' and password='$password'";

$result = mysql_query($query);

if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
    include "login.html";

} else {
    $_SESSION['username'] = "$username";
    include "memberspage.php";
}

?>

 

Link to comment
Share on other sites

There's at lest three different reasons mysql_num_rows($result) won't be equal to 1 and the form will be redisplayed.

 

1) The query failed with an error and mysql_num_rows will be a -1

2) There is no matching row in the table and mysql_num_rows will be a 0

3) There are two or more matching rows in the table and mysql_num_rows will be 2 or more.

 

TeNDoLLA suggested checking what value mysql_num_rows($result) returns by using var_dump(mysql_num_rows($result)); Have you done that?

Link to comment
Share on other sites

OK. Did you do this?

 

There's at lest three different reasons mysql_num_rows($result) won't be equal to 1 and the form will be redisplayed.

 

1) The query failed with an error and mysql_num_rows will be a -1

2) There is no matching row in the table and mysql_num_rows will be a 0

3) There are two or more matching rows in the table and mysql_num_rows will be 2 or more.

 

TeNDoLLA suggested checking what value mysql_num_rows($result) returns by using var_dump(mysql_num_rows($result)); Have you done that?

 

That's really about the only place the problem could be now.

Link to comment
Share on other sites

does it "refresh" for both correct and incorrect login credentials?

 

if not then, i would check to make sure "memberspage.php" is not just sending you right back to your login page.

 

EG. it also needs session_start(); at the top of that page.

 

 

also echo everything out to make sure its correct.

Link to comment
Share on other sites

Pikachu, dude apologize Im really new at this I dont even know how to do the aforementioned.

Penny for your thoughts...or should i say.

Can you tell me how to do that?

Am I simply adding these lines or am i replacing a certain portion of the code with that text?

Sorry man I learn quick. Just need to be shown once.

-SB

 

Link to comment
Share on other sites

seany,

where do I insert that echo command? Anywhere?

-SB

 

just quickly remove

 

if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
    include "login.html";

} else {
    $_SESSION['username'] = "$username";
    include "memberspage.php";
}

 

and replace with this

 

echo mysql_num_rows($result);

 

try that for both correct and incorrect credentials

Link to comment
Share on other sites

Yeah, both....

Im assuming this is not good? lol

 

the 0 is basically saying that it found 0 results when looking through your table...

 

replace the last echo with:

 

echo $username;
echo "<br/>";
echo $password;

 

and make sure it exactly the same as the credentials in the database... (the passwords in your db should be MD5 encrypted)

 

put brackets around your query.. and use `s and also and might have to be in caps or use && see below.

 

$query = ("select * from `users` where `username`='$username' && `password`='$password'");

 

i dont know if this effects anything but its the right way of doing it so its worth a try...

 

also do the same for includes

 

include ("example.php");

 

Link to comment
Share on other sites

You don't need to put parentheses around a string value to assign it to a variable, even if it is a query string. Same goes for include.

 

Because include() is a special language construct, parentheses are not needed around its argument. Take care when comparing return value.

Link to comment
Share on other sites

OK so this is an interesting development...lol

It echos the username ok but the password which yes is in md5 format both in the dbase and the login script which im sure you noticed.

-SB

 

 

sorry i didnt understand that last post too well... so it does echo them correctly or not?

 

 

You don't need to put parentheses around a string value to assign it to a variable, even if it is a query string. Same goes for include.

 

Because include() is a special language construct, parentheses are not needed around its argument. Take care when comparing return value.

hehe i wasn't too sure about that, but it was worth suggesting just in case :P

Link to comment
Share on other sites

sorry lil overzealous there...

no the md5 displayed by the browser does not match the one displayed in phpmyadmin.

Also i dunno if if affects anything but i created the database in phpmyadmin.

Ive read a lil about "double md5'ing (despite the fact I dont really know what that means) is this a possibility here?

-SB

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.