【发布时间】:2021-02-14 03:54:23
【问题描述】:
我正在尝试根据选中的复选框从 PHP 中的 MySQL 数据库中获取数据。 i am fine when a single checkbox is selected then it should fetch me some data from the database, but when two or more checkboxes are selected it is not fetching the right data but coming as if it is only one checkbox selected.
示例:
checkbox1 显示名字,checkbox2 显示姓氏。当 checkbox1 和 checkbox2 被选中时应该显示名字和姓氏,但它只显示名字。
if(isset($_POST["Export"])){
if(isset($firstname)){
$sql = "SELECT firstname from biodata";
$stmt = $pdo->query($sql);
}
elseif(isset($lastname)){
$sql = "SELECT lastname from biodata";
$stmt = $pdo->query($sql);
}
if(isset($firstname && $lastname)){
$sql = "SELECT firstname,lastname from biodata";
$stmt = $pdo->query($sql);
}
}
【问题讨论】:
-
您不必在第三个
isset()中使用&&。仅当设置了isset()的所有参数并且不包含null时,isset($firstname , $lastname)才会返回 true。 -
感谢您的回复,即使它没有解决它...
标签: php checkbox operator-keyword