Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.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 无法从POST获取值_Php_Mysql_Arrays_Forms_Foreach - Fatal编程技术网

Php 无法从POST获取值

Php 无法从POST获取值,php,mysql,arrays,forms,foreach,Php,Mysql,Arrays,Forms,Foreach,这是我创建的更新页面的一部分,如果勾选,我可以将某些图像设置为私有。 这是我的表格: /* MYSQL rows - Photo ID & Privacy */ $photo_id = $row['id']; $photo_private = $row['private']; /* Privacy setting for photo(s) */ if ($photo_private == "1") { echo '<input type

这是我创建的更新页面的一部分,如果勾选,我可以将某些图像设置为私有。 这是我的表格:

/* MYSQL rows - Photo ID & Privacy */

$photo_id = $row['id'];
$photo_private = $row['private'];

    
/* Privacy setting for photo(s) */

if ($photo_private == "1") {

    echo '<input type="checkbox" name="private_photo['.$photo_id.']" value="1" checked>';

       } else {

     echo '<input type="checkbox" name="private_photo['.$photo_id.']" value="0">';

 }

首先,去掉value=0的复选框。这不是你所期望的那样。如果未选中复选框,则根本不会将其发送到服务器。这意味着如果选中它,它将发送值0,因此它将永远无法正确设置

接下来,添加一个具有相同名称和值=0的隐藏输入。如果将此输入置于复选框之前,则如果未选中该复选框,则会将其发送到服务器。如果选中该复选框,它将覆盖该隐藏输入

//ternary - variable holds 'checked' if `$photo_private == 1`, or an empty string if not.
$is_checked = $photo_private == "1" ? 'checked' : '';

//hidden input - Submitted if checkbox is not checked.
echo '<input type="hidden" name="private_photo['.$photo_id.']" value="0">';

//checkbox - overwrites previous hidden input if checked. 
//Utilizes `$is_checked` to check the checkbox by default when appropriate
echo '<input type="checkbox" name="private_photo['.$photo_id.']" value="1" '.$is_checked.'>';
这应该有效,因为如果选中复选框,它将覆盖隐藏输入中的值。如果未选中,则将提交隐藏的输入值

//ternary - variable holds 'checked' if `$photo_private == 1`, or an empty string if not.
$is_checked = $photo_private == "1" ? 'checked' : '';

//hidden input - Submitted if checkbox is not checked.
echo '<input type="hidden" name="private_photo['.$photo_id.']" value="0">';

//checkbox - overwrites previous hidden input if checked. 
//Utilizes `$is_checked` to check the checkbox by default when appropriate
echo '<input type="checkbox" name="private_photo['.$photo_id.']" value="1" '.$is_checked.'>';