从一个脚本执行它时使用标题刷新数据,而另一个脚本不刷新数据?

时间:2017-10-04 21:04:56

标签: php sql refresh

我使用两个脚本,一个用于从SQL中删除,另一个用于添加到数据库。

我遇到的问题是,在运行添加脚本时,它会立即刷新页面以显示更改。然而,当运行删除脚本时,它不会立即刷新它并且似乎它缓存输出?

如果它确实缓存了重定向到的输出,为什么一个脚本显示添加而另一个脚本没有显示删除?

添加脚本

// Set a URL for the user to be redirected to
$header_URL = "Location: ".WEBURL.DOCROOT."pages/parents-evening/{$_SESSION['status']}/";


// SQL statement using the variables from the user to insert into a specific table
$sql = "INSERT INTO $table ($columns) VALUES ($values);";

// Check that the query was successful
if(mysqli_query($conn, $sql))
{
    // Success
    // Closes the database connection
    mysqli_close($conn);
    // Sets the redirect location
    header($header_URL);
    // Exits the script
    exit();
}
else
{
    // Fail
    // Closes the database connection
    mysqli_close($conn);
    // Sets the redirect location
    header($header_URL);
    // Exits the script
    exit();
}

删除脚本

// Set a URL for the user to be redirected to
$header_URL = "Location: ".WEBURL.DOCROOT."pages/parents-evening/{$_SESSION['status']}/";

// SQL statement to delete from the table provided where the ID is equal to either the POST or GET value
$sql = "DELETE FROM {$table} WHERE id = {$_POST['delete_id']}{$_GET['delete_id']}";

// Check the query was successful
if(mysqli_query($conn, $sql))
{
    // Success
    // Closes the database connection
    mysqli_close($conn);
    // Sets the redirect location
    header($header_URL);
    // Exits the script
    exit();
}
else
{
    // Fail
    // Closes the database connection
    mysqli_close($conn);
    // Sets the redirect location
    header($header_URL);
    // Exits the script
    exit();
}

1 个答案:

答案 0 :(得分:0)

似乎问题出现在这个陈述中:

$ sql =“DELETE FROM {$ table} WHERE id = {$ _POST ['delete_id']} {$ _ GET ['delete_id']}”;

如果您从let enrichedUser = case decode $ r2 ^. responseBody of Nothing -> defaultEnrichment u Just e -> e return enrichedUser 获得delete_id,则查询将为:

POST

如果您从$sql = "DELETE FROM {$table} WHERE id = ".$_POST['delete_id']; 获得delete_id,则查询将为:

GET

如果只有一条记录要删除(因为似乎$sql = "DELETE FROM {$table} WHERE id = ".$_GET['delete_id']; 是主键,所以只有一条记录),我建议使用id,因为它会加快删除过程如果您的表中有大量数据。

限制1将告诉数据库只删除一条记录,以便在删除1条记录时停止执行。

您的最终查询将是:

limit 1

POST

$sql = "DELETE FROM {$table} WHERE id = ".$_POST['delete_id']." LIMIT 1";

GET