user2885237
user2885237

Reputation: 61

Refresh page automatically after submitting form

After I submit my data from form I don't see it immediate on my screen, I have to refresh it via browser refresh button.

<form action="" method="post">  

<input type="submit" name="submit"  >

I was using the setTimeout function but it gave me lot of issues in submitting to the database and retrieving from it. I could not debug it properly, and so I removed this function. Without setTimeout, I am able to store in the database and retrieve via the refresh button. But how do I make it immediately auto refresh?

Upvotes: 0

Views: 6451

Answers (3)

FarZan Takhsha
FarZan Takhsha

Reputation: 154

For refresh page use this code:

<META HTTP-EQUIV ='Refresh' Content ='0; URL =/'>

You can use like this end of your code:

<?php echo "<META HTTP-EQUIV ='Refresh' Content ='0; URL =/'>"; ?>

Upvotes: 1

Lelio Faieta
Lelio Faieta

Reputation: 6684

Set your action as: <?php echo $_SERVER['PHP_SELF']?>

and it will do the trick.

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">  

Action is the directive that trigger what to do with the data. If you don't specify it how is the browser supposed to do anithing?

Upvotes: 0

abhay vyas
abhay vyas

Reputation: 146

i have done with the help of jquery and ajax without refresh and page loading html file with ajax

<html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){

            $("#sub").click(function(){

                $.ajax({
                            url: 'dbadd.php',
                            type: 'POST',
                            data: {naam:$("#nm").val()},
                            success:function(response){
                                $("#d1").html(response)
                            }
                        });
            });

        });
    </script>
    </head>
    <form method="post">  
        Name : <input type="text" id="nm" name="name">
        <div id="d1"></div>
    <input type="button" name="submit" id="sub" value="submit">
    </form>
    </html>

php file : adddb.php

<?php
    $con=mysql_connect("localhost","root");
    mysql_select_db("empl",$con);
    $q=mysql_query("insert into emp(name) values ('".$_POST['naam']."')");
    $qq=mysql_query("select name from emp where name='".$_POST['naam']."'");
    while ($data=mysql_fetch_object($qq)) {
        echo $data->name;

    }
?>

Upvotes: 1

Related Questions