未选中php时未注册复选框
我在我的网站上有一个非常基本的功能,用户勾选一个框,如果勾选了这个框,它将执行查询并取消设置会话。如果不是,则不会执行查询,但会破坏会话 这是非常基本的,但由于某些原因,如果复选框未选中,PHP不会注册。如果它被检查,它将工作,而不是后者 这是我的PHP:未选中php时未注册复选框,php,forms,checkbox,Php,Forms,Checkbox,我在我的网站上有一个非常基本的功能,用户勾选一个框,如果勾选了这个框,它将执行查询并取消设置会话。如果不是,则不会执行查询,但会破坏会话 这是非常基本的,但由于某些原因,如果复选框未选中,PHP不会注册。如果它被检查,它将工作,而不是后者 这是我的PHP: if(isset($_POST) && !empty($_POST)){ $la = ($_POST['la'] == "on") ? 1 : 0; // if the box is checked, return 1
if(isset($_POST) && !empty($_POST)){
$la = ($_POST['la'] == "on") ? 1 : 0; // if the box is checked, return 1. if not, return 0
if($la == 1 || $la == 0){
if($la == 1){
// where I execute the query...
session_start();
session_unset();
session_destroy();
redirect('./');
exit();
} else if($la == 0) {
session_start();
session_unset();
session_destroy();
redirect('./');
exit();
}
} else {
redirect('./');
}
}
非常感谢所有帮助:)这是代码,看看它是否有效-
<?php
session_start();//session start should be in the beginning of the code
if(isset($_POST) && !empty($_POST)){
$la = isset($_POST['la']) ? 1 : 0; // if the box is checked, return 1. if not, return 0
if($la == 1 || $la == 0){
if($la == 1){
// where I execute the query...
session_unset();
session_destroy();
redirect('./');
exit();
} else if($la == 0) {
session_unset();
session_destroy();
redirect('./');
exit();
}
} else {
redirect('./');
}
}
这是代码,看看它是否有效-
<?php
session_start();//session start should be in the beginning of the code
if(isset($_POST) && !empty($_POST)){
$la = isset($_POST['la']) ? 1 : 0; // if the box is checked, return 1. if not, return 0
if($la == 1 || $la == 0){
if($la == 1){
// where I execute the query...
session_unset();
session_destroy();
redirect('./');
exit();
} else if($la == 0) {
session_unset();
session_destroy();
redirect('./');
exit();
}
} else {
redirect('./');
}
}
如果我没有弄错,则未选中复选框时不直接发送变量。
未选择“不发送”时,此变量$\u POST['la']。
也许您需要使用此代码来控制此情况:
if (isset($_POST['la'])) {
...
}
如果我没有弄错,复选框未选中时,直接不发送变量。
未选择“不发送”时,此变量$\u POST['la']。
也许您需要使用此代码来控制此情况:
if (isset($_POST['la'])) {
...
}
当HTML在POST中提交表单时| GET it not submit unchecked复选框,因此您需要签入PHP代码isset($_POST['checkbox_name'])@Faraz它似乎在我的站点的其他区域工作?@Faraz同样,如果您在该表单中只有复选框,那么它可能是空的,因为没有其他内容被使用,在表单中提交一个隐藏值以确保表单提交时其不为空当HTML在POST中提交表单时| GET it not submit unchecked复选框,因此您需要检查PHP代码isset($_POST['checkbox_name'])@Faraz它似乎在我网站的其他区域工作?@Faraz也,勾选第2行如果该表单中只有复选框,因此它可能是空的,因为没有其他内容被使用,请在表单中提交一个隐藏值,以确保在提交表单时,在取消勾选复选框的同时,该值不会为空!拼写错误。。哈哈,谢谢你的回答:)var_dump($_POST)同时取消选中复选框修复了它!拼写错误。。哈哈,谢谢你的回答:)