当我再次重新加载页面时,从$_POST
插入数据,我无法删除$_POST
数据和浏览器Cookie。
if($_POST['submit']) {
$title = $_POST['title'];
$location = $_POST['location'];
$description = $_POST['description'];
$sql = "INSERT INTO `room_list` (`id`, room`) VALUES (NULL, '0');";
$query = mysql_query($sql);
if($query){ // True }
else { // False }
unset($_POST[submit]);
unset($_REQUEST);
}
答案 0 :(得分:0)
首先,您应该在尝试将变量分配为变量之前测试POST变量是否可用,将代码升级为使用mysqli
或PDO
并避免重新提交表单,这是常用的header
函数在某些特定操作/表单提交后重定向以避免多次插入
if( isset( $_POST['submit'], $_POST['title'],$_POST['location'],$_POST['description'] ) ){
/* why do these not get used? */
$title = $_POST['title'];
$location = $_POST['location'];
$description = $_POST['description'];
/* Should use `mysqli` or `PDO` - the `mysql` api is deprecated */
$sql = "INSERT INTO `room_list` (`id`, `room`) VALUES (NULL, '0');";
$query = mysql_query( $sql );
header( "Location: " . $_SERVER['SCRIPT_NAME'] . '?status='.$query );
}