petroz Posted September 7, 2009 Share Posted September 7, 2009 Hi Guys, This script isn't reporting any errors, but its not actually authenticating at all. I am not even seeing the echo "Hello"; Any help would be greatly appreciated. <?php include 'db.php'; // Add slashes to the username, and make a md5 checksum of the password. $user = addslashes($_POST['username']); $pass = md5($_POST['password']); $result = mysql_query("SELECT count(bus_id) FROM businesses WHERE password='$pass' AND bus_id='$user' LIMIT 1") or trigger_error('Query failed: ' . mysql_error($db), E_USER_ERROR); $num = mysql_result($result, 0); //$row = mysql_fetch_array($result); //$num = $row['bus_id']; if (!$num) { // When the query didn't return anything, // display the login form. echo "<h3>User Login</h3> <form action='$_SERVER[php_SELF]' method='post'> Username: <input type='text' name='username'><br> Password: <input type='password' name='password'><br><br> <input type='submit' value='Login'> </form>"; } else { // Start the login session session_start(); echo "Hello"; // We've already added slashes and MD5'd the password $_SESSION['username'] = $_POST['username']; $_SESSION['password'] = $_POST['password']; // All output text below this line will be displayed // to the users that are authenticated. Since no text // has been output yet, you could also use redirect // the username to the next page using the header() function. // header('Location: page2.php'); echo "<h1>Welcome</h1>"; echo "You're now logged in. Try visiting <a href='update_info_form.php'>Update Info Form</a>."; } ?> Here is a sample of a user and pw from the db. bus_id password eric f4b00a307fa831ef56ef7117c Quote Link to comment Share on other sites More sharing options...
ram4nd Posted September 7, 2009 Share Posted September 7, 2009 you don't need 2 sessions. Quote Link to comment Share on other sites More sharing options...
Cetanu Posted September 7, 2009 Share Posted September 7, 2009 Try starting the session (session_start() ) at the very beginning of the code... 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.