为什么$_POST将字符串转换为布尔值


Why does $_POST convert string to boolean

我有一个非常奇怪的问题,我想要第二双眼睛。我正在尝试一些应该是非常基本的功能。使用POST发送表单并检索值。

<form action="index.php?a=2" method="post">
                    <input type="hidden" name="pk" value="'. $_GET["c"] .'">
                    <table id="_person_table">
                <tr>
                    <td id = "_person_create_table"> FIRST NAME: </td>
                    <td id = "_table_nr_plate"> <input type="text" name="afn" id="_person_create_input" value="'.$record[0].'"> </td>
                </tr>                   
                <tr>
                    <td id = "_person_create_table"> LAST NAME: </td>
                    <td id = "_table_nr_plate">  <input type="text" name="overwrite_lastname" id="_person_create_input" value="'.$record[1].'"> </td>
                </tr>   
                <tr>
                    <td id = "_person_create_table"> PHONE NUMBER: </td>
                    <td id = "_table_nr_plate"> <input type="text" name="overwrite_phone_number" id="_person_create_input" value="'.$record[2].'"> </td>
                </tr>   
                <tr>
                    <td id = "_person_create_table"> E MAIL: </td>
                    <td id = "_table_nr_plate"> <input type="text" name="aem" id="_person_create_input" value="'.$record[3].'"> </td>
                </tr>
                <tr>
                    <td id = "_person_create_table"> STREET ADRESS: </td>
                    <td id = "_table_nr_plate"> <input type="text" name="asa" id="_person_create_input" value="'.$record[4].'"> </td>
                </tr>
                <tr>
                    <td id = "_person_create_table"> FULL HOUSE NUMBER: </td>
                    <td id = "_table_nr_plate"> <input type="text" name="ahn" id="_person_create_input" value="'.$record[5].'"> </td>
                </tr>
                <tr>
                    <td id = "_person_create_table"> POSTAL CODE:</td>
                    <td id = "_table_nr_plate"> <input type="text" name="apc" id="_person_create_input" value="'.$record[6].'"> </td>
                </tr>
                </table>
                    <center> <input type="image" src="img/alterUser.png" name="submit" alt="Submit" style="width:100px;height:100px; padding-top:1%;"> </center>
                </form>

上面是表单,当我var_dump将每个值分开时,它会给出字符串表示。然而,在index.php上发送和检索的是什么?a=2,则给出以下转储:

array(10) { 
   ["pk"]=> string(8) "10000007"
   ["afn"]=> string(5) "Lisa" 
   ["overwrite_lastname"]=> bool(true) 
   ["overwrite_phone_number"]=> bool(true)
   ["aem"]=> string(26) "lisa@example.com" 
   ["asa"]=> string(19) "not applicable" 
   ["ahn"]=> string(1) "0" 
   ["apc"]=> string(6)

为什么POST中的10个值中有8个如预期,但$_POST["overwrite_lastname"]$_POST["overwrite_phone_number"]转换为布尔值?我没看到。

更新#1:var_dump($record);

array(8){[0]=>string(4)"Lisa"[1]=>string(8)"Dijkstra"[2]=>string(10)"0643482515"[3]=>string(17)"lisa@example.com"[4] =>字符串(19)"不适用"[5]=>字符串(1)"0"[6]string(6)"9743LD"[7]=>string(19)"待实施"}

更新#2:睡了一夜好觉之后,我找到了病因。我正在检查POST值是否设置为:

if($_POST["afn"]!=null&&$_POSD["overwrite_lastname"]=!null;$_POST["overwrite_phone_number"]=!空&amp$_POST["aem"]!=空&amp;$_POST["asa"]!=空&amp$_POST["ahn"]=空&amp$_POST["apc"]!=空)

可以看出我切换了!=to=!以布尔值形式返回的值。至少我学会了!可以用来引用true。

你用错了PHP,试试这个

<form action="index.php?a=2" method="post">
                    <input type="hidden" name="pk" value="<?php echo $_GET["c"]; ?>">
                    <table id="_person_table">
                <tr>
                    <td id = "_person_create_table"> FIRST NAME: </td>
                    <td id = "_table_nr_plate"> <input type="text" name="afn" id="_person_create_input" value="<?php echo $_GET["c"]; ?>"> </td>
                </tr>                   
                <tr>
                    <td id = "_person_create_table"> LAST NAME: </td>
                    <td id = "_table_nr_plate">  <input type="text" name="overwrite_lastname" id="_person_create_input" value="<?php echo $record[0]; ?>"> </td>
                </tr>   
                <tr>
                    <td id = "_person_create_table"> PHONE NUMBER: </td>
                    <td id = "_table_nr_plate"> <input type="text" name="overwrite_phone_number" id="_person_create_input" value="<?php echo $record[1]; ?>"> </td>
                </tr>   
                <tr>
                    <td id = "_person_create_table"> E MAIL: </td>
                    <td id = "_table_nr_plate"> <input type="text" name="aem" id="_person_create_input" value="<?php echo $record[2]; ?>"> </td>
                </tr>
                <tr>
                    <td id = "_person_create_table"> STREET ADRESS: </td>
                    <td id = "_table_nr_plate"> <input type="text" name="asa" id="_person_create_input" value="<?php echo $record[3]; ?>"> </td>
                </tr>
                <tr>
                    <td id = "_person_create_table"> FULL HOUSE NUMBER: </td>
                    <td id = "_table_nr_plate"> <input type="text" name="ahn" id="_person_create_input" value="<?php echo $record[4]; ?>"> </td>
                </tr>
                <tr>
                    <td id = "_person_create_table"> POSTAL CODE:</td>
                    <td id = "_table_nr_plate"> <input type="text" name="apc" id="_person_create_input" value="<?php echo $record[5]; ?>"> </td>
                </tr>
                </table>
                    <center> <input type="image" src="img/alterUser.png" name="submit" alt="Submit" style="width:100px;height:100px; padding-top:1%;"> </center>
                </form>

更新#2:睡了一夜之后,我找到了原因。我正在检查POST值是否设置为:

if($_POST["afn"]!=null&&$_POSD["overwrite_lastname"]=!null;$_POST["overwrite_phone_number"]=!空&amp$_POST["aem"]!=空&amp;$_POST["asa"]!=空&amp$_POST["ahn"]=空&amp$_POST["apc"]!=null)可以看出我切换了!=to=!对于返回为布尔。至少我学会了!可以用来引用true。