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:
Expand|Select|Wrap|Line Numbers
- <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
Expand|Select|Wrap|Line Numbers
- <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>