smezic Posted April 26, 2013 Share Posted April 26, 2013 (edited) Can some one please tell me were this code is bad it for a friend can i cant find out what going wrong with it <?php include("login-header.php"); ?> <?php include("nav.php"); ?> <?php include("info-col.php"); ?> <div id="content"><!-- Start of the login page content. --> <?php // This section processes submissions from the login form. // Check if the form has been submitted: if ($_SERVER['REQUEST_METHOD'] == 'POST') { //connect to database require ('mysqli_connect.php'); // Validate the email address: if (!empty($_POST['email'])) { $e = mysqli_real_escape_string($dbcon, $_POST['email']); } else { $e = FALSE; echo '<p class="error">You forgot to enter your email address.</p>'; } // Validate the password: if (!empty($_POST['psword'])) { $p = mysqli_real_escape_string($dbcon, $_POST['psword']); } else { $p = FALSE; echo '<p class="error">You forgot to enter your password.</p>'; } if ($e && $p){//if no problems // Retrieve the user_id, first_name and user_level for that email/password combination: $q = "SELECT user_id, fname, user_level FROM users WHERE (email='$e' AND psword=SHA1('$p'))"; $result = mysqli_query ($dbcon, $q); // Check the result: if (@mysqli_num_rows($result) == 1) {//The user input matched the database rcoord // Start the session, fetch the record and insert the three values in an array session_start(); $_SESSION = mysqli_fetch_array ($result, MYSQLI_ASSOC); $_SESSION['user_level'] = (int) $_SESSION['user_level']; // Changes the 1 or 2 user level to an integer. $url = ($_SESSION['user_level'] === 1) ? 'admin-page.php' : 'members-page.php'; // Ternary operation to set the URL header('Location: ' . $url); // Makes the actual page jump. Keep in mind that $url is a relative path. exit(); // Cancels the rest of the script. mysqli_free_result($result); mysqli_close($dbcon); } else { // No match was made. echo '<p class="error">The email address and password entered do not match our records.<br>Perhaps you need to register, click the Register button on the header menu</p>'; } } else { // If there was a problem. echo '<p class="error">Please try again.</p>'; } mysqli_close($dbcon); } // End of SUBMIT conditional. ?> thank you for any help you can give Edited April 26, 2013 by smezic Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 26, 2013 Share Posted April 26, 2013 Is there an error message? What is not working? Quote Link to comment Share on other sites More sharing options...
Solution smezic Posted April 26, 2013 Author Solution Share Posted April 26, 2013 i know that the form is post and it is getting the data but once it passes to the mysql query it fails i keep getting this line of the code The email address and password entered do not match our records.Perhaps you need to register, click the Register button on the header menu 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.