我有三个复选框,用户应该检查一到两个选项。
当我检查 2 个选项时,会出现一条错误消息。
$workshop1Day1 = $_POST["workshop1Day1"];
$workshop2Day1 = $_POST["workshop2Day1"];
$workshop3Day1 = $_POST["workshop3Day1"];
$requete = "INSERT INTO Participant ( NameSurname,workshop1Day1,workshop2Day1,workshop3Day1)
VALUES ('$NameSurname', '$workshop1Day1', '$workshop2Day1', '$workshop3Day1')";
$result = @mysql_query($requete);
错误:
Notice: Undefined index: workshop3Day1
然后我尝试了以下代码(例如:如果未选中复选框编号 3),出现相同的错误
$workshop1Day1=' ';
$workshop2Day1='';
$workshop3Day1='';
$workshop1Day1 = $_POST["workshop1Day1"];
$workshop2Day1 = $_POST["workshop2Day1"];
$workshop3Day1 = $_POST["workshop3Day1"];
if (isset($workshop1Day1)&& isset($workshop2Day1)&& !isset($workshop3Day1))
{
$requete = "INSERT INTO Participant ( NameSurname,workshop1Day1,workshop2Day1,workshop3Day1)
VALUES ('$NameSurname', '$workshop1Day1', '$workshop2Day1', '$workshop3Day1')";
$result = @mysql_query($requete);
我知道 isset 是解决方案,但如何解决?