mallen Posted April 6, 2008 Share Posted April 6, 2008 My login form works ok in Firefox but fails in IE. It sends the user to the index page. Any ideas? <?php session_start(); $query= "SELECT id, email, password, status FROM `members` " ."WHERE `email`='".$_POST["email"]."' " ."AND `password`= '".$_POST["password"]."' " ."LIMIT 1"; $result= mysql_query($query) OR die( mysql_error() ); if ( mysql_num_rows($result) == 1 ) { // retrieve the resultset as an associative array $userRecord= mysql_fetch_assoc($result); $_SESSION['id']= $userRecord['id']; $_SESSION['status']= $userRecord['status']; // redirect based on the $userRecord['status'] value here switch ($userRecord['status']) { case 1: $location= "page1.php"; break; case 2: $location= "page2.php"; break; case 3: $location= "page3.php"; break; } header("Location: $location"); } ?> HTML HERE..... <form action="" method="post"> <label>Email <input type="text" name="email" id="email" /> </label> <label>Password <input type="password" name="password" id="password" /> </label> <label> <input type="submit" name="submit" id="submit" value="submit" /> </label> </form> Link to comment https://forums.phpfreaks.com/topic/99773-login-form-does-not-work-in-ie/ Share on other sites More sharing options...
maexus Posted April 6, 2008 Share Posted April 6, 2008 From what I see, as soon as the page loads, it tries to load post variables that I assume would come from the form at the bottom? Well, that won't work because the query runs before the form is displayed, unless I'm wrong about the form at the bottom supplying the data used in the query. Then, since there is no post variables, I'm assuming $userRecord['status'] is NULL so the switch cause doesn't assign $location to anything and the header call redirects to index because of this. I could be WAY off base as I only skimmed it because I'm at work... Actually, I should be working right now Link to comment https://forums.phpfreaks.com/topic/99773-login-form-does-not-work-in-ie/#findComment-510277 Share on other sites More sharing options...
mallen Posted April 6, 2008 Author Share Posted April 6, 2008 But it works in Firefox. Strange. And I have to have the code at the top and the form at the bottom or I get headers sent errors. Link to comment https://forums.phpfreaks.com/topic/99773-login-form-does-not-work-in-ie/#findComment-510281 Share on other sites More sharing options...
maexus Posted April 6, 2008 Share Posted April 6, 2008 <?php if(isset($_POST['submit'])){ //the code you have before the form } ?> //the form This will make it so that the code does not run unless the form has been submitted. Link to comment https://forums.phpfreaks.com/topic/99773-login-form-does-not-work-in-ie/#findComment-510282 Share on other sites More sharing options...
mallen Posted April 6, 2008 Author Share Posted April 6, 2008 Thanks I tried that and it still won't work. Link to comment https://forums.phpfreaks.com/topic/99773-login-form-does-not-work-in-ie/#findComment-510579 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.