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

}
?>

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.