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 Link to comment https://forums.phpfreaks.com/topic/173377-session-not-logging-in/ Share on other sites More sharing options...
ram4nd Posted September 7, 2009 Share Posted September 7, 2009 you don't need 2 sessions. Link to comment https://forums.phpfreaks.com/topic/173377-session-not-logging-in/#findComment-913965 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... Link to comment https://forums.phpfreaks.com/topic/173377-session-not-logging-in/#findComment-913978 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.