Squirtle
Squirtle

Reputation: 151

Issue with uploading data into database

I am facing problem in sending data to database. The problem is every time i refresh the page it automatically send the previous data. Can any one help.

if (isset($_POST['Posts'])) {
    if (isset($_POST['t']) && isset($_POST['i']) && isset($_POST['P'])) {
        $title = $_POST['t'];
        $idea = $_POST['i'];

        if (!empty($title) && !empty($idea)) {
            $query = "INSERT INTO `updates` VALUES ('".mysql_real_escape_string($title)."')";
            if ($query_run = mysql_query($query)) { } 
            else {
                echo 'Sorry ,we could\'t register you at this time.Try again later';
            } 
        }                    
    }
}

Upvotes: 0

Views: 63

Answers (1)

Wiram Rathod
Wiram Rathod

Reputation: 1919

Clear your post data after insert in db. Add below code after insertion db code.

$_POST = array();

like inside your if block

... 
 if ($query_run = mysql_query($query)) { $_POST = array(); } 
...

Upvotes: 1

Related Questions