Issue with uploading data into database

2019-03-06 03:49发布

问题:

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';
            } 
        }                    
    }
}

回答1:

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(); } 
...


标签: php mysql mysqli