Php form submission Solution

Source: Internet
Author: User

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">

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.