main.php ------------------ <? echo $msg; ?> <form action="process.php" method="post"> <input type="text" name="name"> <input type="hidden" name="action" value="vua"> <input type="submit" value="submit"> </form> process.php ---------------------- <? if($action=="vua") { $msg="Hello $name"; header("Location: ".$HTTP_REFERER); exit(); } ?> Hi, I have created above php files. user will type his/her name in input box and clicking on submit button, process.php will check and send a value (name) in $msg variable and redirect to referer page. Then referer page will show the value of $msg But this script is not working( Please help me
Why not do everything from one file? Try this: <? if ( isset( $_POST['name'] ) { echo 'hello' . htmlentities( $_POST['name'] ) . '<br />'; } ?> <form action="process.php" method="post"> <input type="text" name="name"> <input type="hidden" name="action" value="vua"> <input type="submit" value="submit"> </form> PHP: Brew
oops, you're right. I must have missed that when copying the original code. Thanks for pointing it out. Brew
if($action=="vua") { $msg="Hello $name"; header("Location: ".$HTTP_REFERER); exit(); } you should read about globals if($_POST['action']=="vua") { $msg="Hello $_POST['name']"; header("Location: ".$_SERVER['HTTP_REFERER']); exit(); }
I have used if($_POST['action']=="vua") { $msg="Hello ".$_POST['name']; header("Location: ".$_SERVER['HTTP_REFERER']); exit(); } Not responsing. msg.php is not getting the value of $msg By the by, how process.php will send the value of $msg ?????
What exactly do you want to achieve? You could use something like this, but it just doesn't make sense why would you want it this way: In main.php replace this: <? echo $msg; ?> PHP: with this <? if (isset($_GET['message'])) echo $_GET['message']; ?> PHP: process.php should contain this code (i took the code version from coches): if($_POST['action']=="vua") { $msg="Hello ".$_POST['name']; header("Location: ".$_SERVER['HTTP_REFERER']."?message=".$msg); exit(); } PHP: Didn't check the code for errors and vulnerabilites, but just try it out and explain what exactly you want...
if($_POST['action']=="vua") { $msg="Hello ".$_POST['name']; echo $_SERVER['HTTP_REFERER']; header("Location: ".$_SERVER['HTTP_REFERER']); exit(); } PHP: What do you get? Peace,
Yes, I have write the scripts like below and working very well as my requirement special thanks and repu added msg.php ------------- <? session_start(); session_register("msg"); echo $msg; ?> <form action="process.php" method="post"> <input type="text" name="name"> <input type="hidden" name="action" value="vua"> <input type="submit" value="submit"> </form> process.php ------------------- <? session_start(); session_register("msg"); if($_POST['action']=="vua") { $msg="Hello ".$_POST['name']; header("Location: msg.php"); exit(); } ?>