1 回答

TA貢獻1890條經驗 獲得超9個贊
只需更改檢查值的順序并使用 elseif
您還可以刪除相當多的重復代碼。
$pdo = new PDO("mysql:host=localhost;dbname=liamed", "root", "");
$q = "insert into users
(nume,prenume,inventar)
values(:nume,:prenume,:obiecte)";
$r = $pdo->prepare($q);
$obiecte = false;
if (isset($_POST['telefonCheck']) && isset($_POST['laptopCheck'])) {
$obiecte = 'laptop si telefon';
} elseif (isset($_POST['laptopCheck'])) {
$obiecte = 'laptop';
} elseif (isset($_POST['telefonCheck'])) {
$obiecte = 'telefon';
}
if ( $obiecte ) { // only run if one of the above if's changed this from false
$r->execute(array(":nume" => $_POST['nume'],
":prenume" => $_POST['prenume'],
":obiecte"=>$obiecte)
);
}
- 1 回答
- 0 關注
- 141 瀏覽
添加回答
舉報