Jump to content

[SOLVED] problem in redirecting.....


saradrungta

Recommended Posts

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

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");
   }
}

}
?>

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");
}
}

}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.