Php form submission is not the first time to write a form submission, but it still encounters an unsolved problem. After studying for nearly one day, I asked N + netizens and finally solved the problem. The process was rather tortuous. Thank you for your help. Record it here and you won't be able to fall down in the same place in the future!
The database is bbs, and the table is test. three fields are id, name, and sex. The id is auto_increment.
The content of the php file conn. php connecting to the database is
$ Conn = @ mysql_connect ("localhost", "root", "") or die ("database link error ");
Mysql_select_db ("bbs", $ conn );
Mysql_query ("set names 'gbk'"); // use GBK Chinese encoding;
Table single page: add2.php. Content:
Include ("conn. php ");
If ($ _ POST ['submit ']) {
$ SQL = "insert into test (id, name, sex) values ('', '$ _ POST [name]', '$ _ POST [sex]') ";
Mysql_query ($ SQL); echo "successful! ";
}
?>
Where was the previous error? $ _ POST ['submit '] $ _ POST [name] remember to use uppercase letters ~~~
Is the syntax like this? Strange. Remember it first. I will understand it later.
Note: 1. $ _ POST [] must be capitalized. No matter where it is.
2. the submitted Button must contain name and value. name = "submit" value = "".
3. The action is to be submitted to the PHP file.
4. solve the problem of Chinese garbled characters on the page: write and delete in the head , Add