batstanggt Posted July 5, 2011 Share Posted July 5, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/ Share on other sites More sharing options...
batstanggt Posted July 5, 2011 Author Share Posted July 5, 2011 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238416 Share on other sites More sharing options...
abrahamgarcia27 Posted July 5, 2011 Share Posted July 5, 2011 try moving the session_start(); to the beginning of the php script Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238444 Share on other sites More sharing options...
TeNDoLLA Posted July 5, 2011 Share Posted July 5, 2011 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". Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238446 Share on other sites More sharing options...
batstanggt Posted July 5, 2011 Author Share Posted July 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238581 Share on other sites More sharing options...
batstanggt Posted July 6, 2011 Author Share Posted July 6, 2011 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238805 Share on other sites More sharing options...
Pikachu2000 Posted July 6, 2011 Share Posted July 6, 2011 Add this to the top of the script, before the session_start() call. See if any errors are generated. ini_set('display_errors', 'On'); error_reporting(-1); Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238809 Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2011 Share Posted July 6, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238810 Share on other sites More sharing options...
batstanggt Posted July 6, 2011 Author Share Posted July 6, 2011 Pikachu, I put that code before the session_start(); no errors but no change either. Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238815 Share on other sites More sharing options...
Pikachu2000 Posted July 6, 2011 Share Posted July 6, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238818 Share on other sites More sharing options...
seany123 Posted July 6, 2011 Share Posted July 6, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238819 Share on other sites More sharing options...
batstanggt Posted July 6, 2011 Author Share Posted July 6, 2011 thanks for the reply seany. Same result for both correct and incorrect credentials. Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238822 Share on other sites More sharing options...
seany123 Posted July 6, 2011 Share Posted July 6, 2011 echo this: mysql_num_rows($result) Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238824 Share on other sites More sharing options...
batstanggt Posted July 6, 2011 Author Share Posted July 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238825 Share on other sites More sharing options...
batstanggt Posted July 6, 2011 Author Share Posted July 6, 2011 seany, where do I insert that echo command? Anywhere? -SB Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238826 Share on other sites More sharing options...
seany123 Posted July 6, 2011 Share Posted July 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238827 Share on other sites More sharing options...
batstanggt Posted July 6, 2011 Author Share Posted July 6, 2011 thank you so much for such a prompt response. I did that now the page just loads a '0' at the top left corner of the browser.... Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238828 Share on other sites More sharing options...
seany123 Posted July 6, 2011 Share Posted July 6, 2011 thank you so much for such a prompt response. I did that now the page just loads a '0' at the top left corner of the browser.... for both correct and incorrect credentials? Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238829 Share on other sites More sharing options...
batstanggt Posted July 6, 2011 Author Share Posted July 6, 2011 Yeah, both.... Im assuming this is not good? lol Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238830 Share on other sites More sharing options...
seany123 Posted July 6, 2011 Share Posted July 6, 2011 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"); Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238831 Share on other sites More sharing options...
Pikachu2000 Posted July 6, 2011 Share Posted July 6, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238835 Share on other sites More sharing options...
batstanggt Posted July 6, 2011 Author Share Posted July 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238836 Share on other sites More sharing options...
seany123 Posted July 6, 2011 Share Posted July 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238838 Share on other sites More sharing options...
batstanggt Posted July 6, 2011 Author Share Posted July 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238841 Share on other sites More sharing options...
batstanggt Posted July 6, 2011 Author Share Posted July 6, 2011 the username does match though... Quote Link to comment https://forums.phpfreaks.com/topic/241110-login-page-just-refreshes/#findComment-1238842 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.