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"); } } } ?> Link to comment https://forums.phpfreaks.com/topic/141454-solved-problem-in-redirecting/ 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"); } } } ?> Link to comment https://forums.phpfreaks.com/topic/141454-solved-problem-in-redirecting/#findComment-740417 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"); } } } ?> Link to comment https://forums.phpfreaks.com/topic/141454-solved-problem-in-redirecting/#findComment-740425 Share on other sites More sharing options...
saradrungta Posted January 19, 2009 Author Share Posted January 19, 2009 thanks guys..... Link to comment https://forums.phpfreaks.com/topic/141454-solved-problem-in-redirecting/#findComment-740523 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.