It is not the first time to write a form and submit it, but I still encountered an unsolvable problem. After studying for nearly a day, I asked more than N netizens, and finally solved the problem. The process was quite tortuous. Thank you for your help. Record here. You can't fall down in the same place in the future!
data base Is bbs, and the table is test The 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 code;
Form page: add2.php. The content is:
<?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 a name"/>
<input type="text" name="sex" value="Enter gender"/>
<input type="submit" name="submit" value="Submit"/>
</form>
Where were the previous mistakes$_ POST ['submit '] $_POST [name] Remember to capitalize~~~
Is grammar like this? Strange. Remember first. I will understand later.
Note: 1. $_POST [] must be capitalized. No matter where.
2. The submitted button must include name and value. name="submit" value=" "
3. The action should be submitted to the php file
4. Solve the Chinese page Garbled code Problem: write and delete<meta http equiv="Content Type" content="text/html; charset=utf-8"/>in the head, and add<meta http equiv="Content Type" content="text/html; charset=gb2312">