Restrict next page

Dear Sir,

I have following codes

[php] <?php
$country="";
$capital="";
if (isset($_POST[‘submit’])){
$country=$_POST[‘text1’];
$capital=$_POST[‘text2’];

if (empty($country) || empty($capital)){
die ("<script> alert('Please fill both boxes')</script>");
}else{
echo "<script> alert('The capital of  $country is $capital')</script>";
}
if (isset($_POST['clear'])){
$country="";
$capital="";
}
}
?>
<html>
<head>
<title>Result on same page</title>
</head>
<body>
<center>
  <form name="form1" action="" method="post">
	Country<input type="text" name="text1" value="<?php echo $country;?>"><br>
	Capital<input type="text" name="text2" value="<?php echo $capital;?>"> <br><br>
	<input type="submit" name="submit" value="Result">
	<input type="submit" name="clear" value="clear">
  </form>
</center>
</body>
</html>

[/php]

When I enter values in boxes and press Display Button then it shows result on same page
But…
When When I press Display Button without entring any values in textboxes then browser goes to second page.

With empty boxes it show result on next page.

I want it to remain in same brower in both case, Filled textbox or Empty texbexes.

Please help

what other page does it go to?

Appears same page but blank, you can run my codes on your pc to seeing actual problem.

ah, i see it now.
[php]die ("");[/php]

This line stops php execution after printing this line. So nothing afterwards will be handled. Just change it from die to a normal echo and it should work as expected.

Sponsor our Newsletter | Privacy Policy | Terms of Service