soc86 Posted September 15, 2011 Share Posted September 15, 2011 I am trying to create a login form. But when i enter the correct username and password it will not redirect me to the correct mage (index.php). Can anyone help, my code is below: <?php session_start(); if(isset($_SESSION["manager"])){ header("location: index.php"); exit(); } ?> <?php //Parse the log in form if the user has filled it out and pressed "Log In" if(isset($_POST["username"])&& isset($_POST["password"])){ $manager=preg_replace('#[^A-Za-z0-9]#i','',$_POST["username"]); $password=preg_replace('#[^A-Za-z0-9]#i','',$_POST["password"]); //Connect to the MySQL database include"../storescripts/connect_to_mysql.php"; $sql=mysql_query("SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1"); //query the person //-----MAKE SURE PERSON EXISTS IN DATABASE ----- $existCount=mysql_num_rows($sql); //count the row nums if($existsCount==1){ //evaluate the count while($row=mysql_fetch_array($sql)){ $id=$row["id"]; } $_SESSION["id"]=$id; $_SESSION["manager"]=$manager; $_SESSION["password"]=$password; header("location: ../index.php"); exit(); }else{ echo 'That information is incorrect try again <a href="admin_login.php">Click Here</a>'; exit(); } } ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 15, 2011 Share Posted September 15, 2011 Echo the query string and make sure it contains the values you'd expect it to contain. Echo the value of mysql_num_rows() to make sure it isn't zero. Paste the echoed query string into phpMyAdmin and see what results it returns. What application is that code from? Quote Link to comment Share on other sites More sharing options...
soc86 Posted September 16, 2011 Author Share Posted September 16, 2011 What do you mean application, Its coded by myself? Quote Link to comment Share on other sites More sharing options...
soc86 Posted September 16, 2011 Author Share Posted September 16, 2011 run the quey and $existCount is equal to 1? Quote Link to comment Share on other sites More sharing options...
RobertP Posted September 20, 2011 Share Posted September 20, 2011 i recommend encrypting your password $password = hash('sha1',$password); and make the password row varchar(40) 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.