Recently, when I was working on a company project, I found a strange problem. When I submitted a normal form, I found that the submitted value could not be obtained normally, I was confused at the beginning. At the beginning, I thought it was a problem with my service and could not normally write data into the database. Later I detected SQL statements and found that, the original problem occurred when obtaining data, and the obtained data was empty. Later, a debug found that all the variables originally submitted to the backend were no longer the expected variables, it turned out to be converted by PHP.
The test code is as follows:
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> test form submission </title>
</Head>
<Body>
<Form action = "" method = "post">
Name: <input type = "text" value = "test" name = "info. name"/> <br/>
Password: <input type = "text" value = "hahaha" name = "info. pwd"/> <br/>
QQ: <input type = "text" value = "961412" name = ". info. qq"/> <br/>
Address: <input type = "text" value = "zhejiang" name = "info | address"/> <br/>
Tel: <input type = "text" value = "123456789" name = "1 -- phone"/> <br/>
Gender: <input type = "radio" name = "info_gender" value = "1" checked> male <input type = "radio" name = "info_gender" value = "2"> female <br/>
<Button type = "submit" name = "submit" value = "> commit </button>
</Form>
</Body>
</Html>
<? Php
If ($ _ POST ){
Echo '<pre/> ';
Var_export ($ _ POST );
}
?>
Code example 1
The result is as follows:
Figure 1
As you can see, all. are converted into _ underscores by the backend. In order to test other symbols, the above test has been conducted. So far, only the dot (.) has been found (.) will be converted to underscores (_), so I take info for granted at the backend. name cannot be accessed because it has been converted into info_name.
In the future, we will try not to use a. name when using a form.