A solution to the PHP form submission problem

  • 2020-03-31 21:38:26
  • OfStack

Here is a record, later can not fall in the same place!
The database is BBS and the table is test. The three fields are id,name and sex respectively. Id for the auto_increment.
The contents of the conn. PHP file connecting to the database are
 
$conn = @ mysql_connect("localhost", "root", "") or die(" Database link error "); 
mysql_select_db("bbs", $conn); 
mysql_query("set names 'GBK'"); //Use GBK Chinese code;

Form page: add2.php. Content as follows:
 
<?php 
include("conn.php"); 
if($_POST['submit']){ 
$sql="insert into test (id,name,sex) values ('','$_POST[name]','$_POST[sex]')"; 
mysql_query($sql); echo " Success! "; 
} 
?> 
<form action="add2.php" method="post"> 
<input type="text" name="name" value=" Enter the name " /> 
<input type="text" name="sex" value=" Enter the gender " /> 
<input type="submit" name="submit" value=" submit " /> 
</form> 

What was the mistake? $_POST['submit'] $_POST[name] remember to capitalize ~~~
Is that the grammar? Strange ah. Let's just remember. We'll see.
Note: 1.$_POST[] must be capitalized. Anywhere.
2. Be sure to write name and value on the submit button. Name ="submit" value ="  "
3. Action is committed to a PHP file
4. Solve the problem of Chinese garbled code on the page: write delete < in the head; Meta HTTP - equiv = "content-type" Content = "text/HTML. Charset = utf-8 "/ > , plus < Meta HTTP - equiv = "content-type" Content = "text/HTML. Charset = gb2312 ">

Related articles: