0

Dear Sir,

I have following codes

    <?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>

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

3
Contributors
2
Replies
14
Views
3 Years
Discussion Span
Last Post by furqan219
0

remove this line
die ("<script> alert('Please fill both boxes')</script>");
to this one
echo ("<script> alert('Please fill both boxes')</script>");

0

For Page Protection use this on top of the page

session_start();
if($_SESSION[type]!='ACTAdmin'){
header("location:index.php");
exit();
}

please use type of the user.

Edited by pritaeas: Removed self-promotion link.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.