GateGuardian Posted June 25, 2008 Share Posted June 25, 2008 <?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? Quote Link to comment Share on other sites More sharing options...
Xyphon Posted June 25, 2008 Share Posted June 25, 2008 Well it has to be if($count=="1") And you said the right password works fine. Then why not use the right password? Quote Link to comment Share on other sites More sharing options...
GateGuardian Posted June 25, 2008 Author Share Posted June 25, 2008 Well it has to be if($count=="1") And you said the right password works fine. Then why not use the right password? Changed it Still does the same thing :/ Its a login form, i needed it to redirect the user if they haven't used the right password. Quote Link to comment Share on other sites More sharing options...
ionik Posted June 26, 2008 Share Posted June 26, 2008 ..try this if it doesnt work see what the result is from the num_rows if ($count != 1) { echo 'Bug Testing!'; } else { //everything else } Quote Link to comment Share on other sites More sharing options...
GateGuardian Posted June 26, 2008 Author Share Posted June 26, 2008 ..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 ^^ Quote Link to comment Share on other sites More sharing options...
Xyphon Posted June 26, 2008 Share Posted June 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 26, 2008 Share Posted June 26, 2008 Firstly: Don't use session_register, it's deprecated. Secondly, check your query and make sure display_errors is on in php.ini. Quote Link to comment Share on other sites More sharing options...
GateGuardian Posted June 26, 2008 Author Share Posted June 26, 2008 Firstly: Don't use session_register, it's deprecated. Secondly, check your query and make sure display_errors is on in php.ini. Ok with the sessions display_errors is on I can bundle the full script together if someone wants to take a look at it.. Quote Link to comment Share on other sites More sharing options...
Xyphon Posted June 26, 2008 Share Posted June 26, 2008 I really wouldn't suggest using num_rows, there's much easier ways. Look at a demo script, using cookies. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 26, 2008 Share Posted June 26, 2008 I really wouldn't suggest using num_rows, there's much easier ways. Look at a demo script, using cookies. I'm curious to know what you mean. Quote Link to comment Share on other sites More sharing options...
Xyphon Posted June 26, 2008 Share Posted June 26, 2008 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'); ?> Quote Link to comment Share on other sites More sharing options...
GateGuardian Posted June 26, 2008 Author Share Posted June 26, 2008 $count must equal 1 otherwise the session variables wouldn't be set? I think i may need to recode the thing from scratch Quote Link to comment 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.