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
Copy codeThe Code is as follows:
$ 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:
Copy codeThe Code is 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 "successful! ";
}
?>
<Form action = "add2.php" method = "post">
<Input type = "text" name = "name" value = "input name"/>
<Input type = "text" name = "sex" value = "input gender"/>
<Input type = "submit" name = "submit" value = "submit"/>
</Form>
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 <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> in the head, add <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">