Jump to content

Why can't I login?


soc86

Recommended Posts

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();
    }
}
?>

Link to comment
Share on other sites

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?

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.