Dear Sir,

I have following codes

    if (isset($_POST['submit'])){

    if (empty($country) || empty($capital)){
    die ("<script> alert('Please fill both boxes')</script>");
    echo "<script> alert('The capital of  $country is $capital')</script>";
    if (isset($_POST['clear'])){
    <title>Result on same page</title>
      <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">

When I enter values in boxes and press Display Button then it shows result on same page
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

Recommended Answers

All 2 Replies

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

For Page Protection use this on top of the page


please use type of the user.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.