saradrungta Posted January 19, 2009 Share Posted January 19, 2009 hi friends, i hv written following code. the problem i m facing is without displaying the alert box the page get redirected. instead i want that when user click 'ok' then the page should be redirected. pls help...what should i change <?php require("config.php"); if(isset($_POST['submit'])){ if(!empty($_POST['uname'])&&($_POST['password'])){ $uname = $_POST['uname']; $password = $_POST['password']; $sql = "SELECT uid, pass FROM user WHERE(uid='$uname' AND pass='$password')"; $result = mysql_query($sql) or die (mysql_error()); $numrow = mysql_num_rows($result); $rows=mysql_fetch_assoc($result); if(!$numrow){ echo '<script>alert("Invalid Username/Password");</script>'; header("Location:index.php"); } else{ $_SESSION['uid']=$rows['uid']; echo $_SESSION['uid']; header("Location:member.php"); } } } ?> Quote Link to comment Share on other sites More sharing options...
phparray Posted January 19, 2009 Share Posted January 19, 2009 This is not tested but should work. using a js redirect instead of php's header. <?php require("config.php"); if(isset($_POST['submit'])){ if(!empty($_POST['uname'])&&($_POST['password'])){ $uname = $_POST['uname']; $password = $_POST['password']; $sql = "SELECT uid, pass FROM user WHERE(uid='$uname' AND pass='$password')"; $result = mysql_query($sql) or die (mysql_error()); $numrow = mysql_num_rows($result); $rows=mysql_fetch_assoc($result); if(!$numrow){ echo '<script> alert("Invalid Username/Password"); location.href="index.php"; </script>'; } else{ $_SESSION['uid']=$rows['uid']; echo $_SESSION['uid']; header("Location:member.php"); } } } ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted January 19, 2009 Share Posted January 19, 2009 Remove the ECHO before the Header and it should work fine. hi friends, i hv written following code. the problem i m facing is without displaying the alert box the page get redirected. instead i want that when user click 'ok' then the page should be redirected. pls help...what should i change <?php require("config.php"); if(isset($_POST['submit'])){ if(!empty($_POST['uname'])&&($_POST['password'])){ $uname = $_POST['uname']; $password = $_POST['password']; $sql = "SELECT uid, pass FROM user WHERE(uid='$uname' AND pass='$password')"; $result = mysql_query($sql) or die (mysql_error()); $numrow = mysql_num_rows($result); $rows=mysql_fetch_assoc($result); if(!$numrow){ echo '<script>alert("Invalid Username/Password");</script>'; header("Location:index.php"); } else{ $_SESSION['uid']=$rows['uid']; echo $_SESSION['uid']; header("Location:member.php"); } } } ?> Quote Link to comment Share on other sites More sharing options...
saradrungta Posted January 19, 2009 Author Share Posted January 19, 2009 thanks guys..... 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.