fetch data from text box and compare on database for a log in page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sol37
    New Member
    • May 2014
    • 1

    fetch data from text box and compare on database for a log in page

    Hello,
    I am creating a log in page where the user enters the email and the password.
    The app will check with the database if the user and the password are correct.
    My issue is that when the php page retrieved the information on the text boxes, there is no data and therefore the user does not exist on the database.
    The code is ass follows:

    the index.php page is:
    Code:
    <html>
        <head>
            <meta charset="UTF-8">
            <title>Pet Service Catalogue</title>
        </head>
        <body>
            <h1 style="text-align:center;"><img src="cat's paw.jpg" width="150" height="150" alt="cat's paw"/> Welcome to Pet Service Catalogue</h1>
            <p style="text-align:center;">Please enter your Log in Details:</p>
    
            <form style ="text-align:center;" method="POST" name="LogIN" action="log_in.php" enctype="multipart/form-data">
                <p style="text-align:center;"> Email: <input type="text" name="user_email" value=""/></p>
                <p style="text-align:center;"> Password: <input type="password" name="user_password" value="" /></p>
                <input type="submit" value="Log In" name="LogIN" />
            </form>
            <form style="text-align:center;" name="registerprovider" action="registerprovider.php">
                <p style="text-align:center;">Not Registered?:</p>
                <input type="submit" value="Register Service Provider" name="Register Service Provider" />
            </form>
            <form style="text-align:center;" name="registerowner" action="registerowner.php">
                <input type="submit" value="Register Pet Owner" name="Registerownerbutton" />
            </form>
        </body>
    </html>[COE]

    the log_in.php page

    Code:
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <body>
    
            <?php
    // Create connection
            $con = mysqli_connect('localhost', 'root', 'root', 'PetServiceCatalogue') or die("Failed to connect to database:" . mysqli_error($con));
    
    
            //Get user details and put them on varaiables
            $user_email = mysqli_real_escape_string($con, $_POST['user_email']);
            $user_password = mysqli_real_escape_string($con, $POST['user_password']);
    
            if (!empty($user_email) && !empty($user_password))
            {
            //look up for user details on the database
            $query = "SELECT * FROM owner, provider WHERE email = '$user_email' AND password = SHA('$user_password') ";
            $data = mysqli_query($con, $query);
            $result = mysqli_num_rows($data);
            printf("Number of rows %d \n", $result);
            if ($result == 1) {
                //The log in has found the user
                $row = mysqli_fetch_array($data);
                $user_email = $row('email');
                $user_password = $row('password');
                header("location: ownerhomepage.php");
            } else {
                //the user name or password are incorrect
                echo "Wrong user email and password";
            }
            }
            else
            {
                
                echo ' You must enter the user email and user password';
                ?>
            <form name="back to index" action="index.php">
                <input type="submit" value="Back to Log in page" name="Back to Log in page" /> </form>
            <?php
            }
            mysqli_close($con);
            ?>
        </body>
    </html>
    any help please
    Last edited by Dormilich; May 27 '14, 07:20 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    1) what does POST contain? (check with var_dump())

    2) there are syntax errors on log_in.php:27/28

    3) the location header won’t work.

    Comment

    • kahan
      New Member
      • Oct 2015
      • 1

      #3
      hi,
      on line 15 $_POST.
      for location use header("Locatio n: ownerhomepage.p hp");
      thanks

      Comment

      Working...