Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未选中复选框时未定义的值_Php - Fatal编程技术网

Php 未选中复选框时未定义的值

Php 未选中复选框时未定义的值,php,Php,我有这个注册码。我希望人们决定他们是否希望被添加到电子邮件列表服务。选中该框后,代码将正确执行,但我得到: 注意:未定义的索引:第21行C:\xampp\htdocs\website\register.php中的邮件列表 当复选框未选中时。下面是代码。我不擅长编程,所以在回应时请假装我很笨。谢谢 <tr><td>Add me to your listserve:</td><td><input type="checkbox" name=

我有这个注册码。我希望人们决定他们是否希望被添加到电子邮件列表服务。选中该框后,代码将正确执行,但我得到:

注意:未定义的索引:第21行C:\xampp\htdocs\website\register.php中的邮件列表

当复选框未选中时。下面是代码。我不擅长编程,所以在回应时请假装我很笨。谢谢

    <tr><td>Add me to your listserve:</td><td><input type="checkbox" name="maillist">  </td></tr>

    $name=mysql_real_escape_string($_POST['name']);
    $dob=mysql_real_escape_string($_POST['dob']);
    $loginid=mysql_real_escape_string($_POST['loginid']);
    $password=mysql_real_escape_string($_POST['password']);
    $emailaddress=mysql_real_escape_string($_POST['emailaddress']);
    $description=mysql_real_escape_string($_POST['description']);
    $maillist=$_POST['maillist'];

    mysql_query("INSERT INTO demographics    values('$name','$dob','$loginid','$password','$description')") or DIE(mysql_error());

    if($maillist==true){
      mysql_query("INSERT INTO maillist values('$name','$emailaddress')") or DIE(mysql_error());
    }
将我添加到您的列表服务:
$name=mysql\u real\u escape\u字符串($\u POST['name']);
$dob=mysql\u real\u escape\u字符串($\u POST['dob']);
$loginid=mysql\u real\u escape\u字符串($\u POST['loginid']);
$password=mysql\u real\u escape\u字符串($\u POST['password']);
$emailaddress=mysql\u real\u escape\u字符串($\u POST['emailaddress']);
$description=mysql\u real\u escape\u字符串($\u POST['description']);
$maillist=$_POST['maillist'];
mysql_query(“插入到人口统计值(“$name”、“$dob”、“$loginid”、“$password”、“$description”)中)或DIE(mysql_error());
如果($maillist==true){
mysql_查询(“插入邮件列表值('$name','$emailaddress'))或死亡(mysql_错误());
}

如果未选中复选框,则不会设置
邮件列表。在使用POST['maillist']
之前,请检查它是否位于POST数组中

$maillist=isset($_POST['maillist']) ? $_POST['maillist'] : '';

HTML表单不会为未选中的复选框创建POST变量。您需要检查变量是否存在,以了解是否已检查:

$maillist = isset($_POST['maillist']);

您必须检查变量是否已设置:

<input type="checkbox" name="maillist" value= true>

if(isset($_REQUEST['maillist']) {
....
}

如果(isset($_请求['maillist'])){
....
}

如果未选中该复选框,则将通过表单发送no值,以便您可以执行以下操作:
$maillist=isset($\u POST['maillist'])
提问前请先回答。这个问题以前已经回答过几千次了。我明白了。谢谢你的帮助。另外,我试图搜索答案,但找不到。下次我会更加努力。