Make a note of it here, so you can’t fall down in the same place in the future!
The database 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 that connects to the database is
Copy the code The 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;
Form page: add2.php. The content is:
Copy code The code is as follows:
include("conn.php") ;
if($_POST['submit']){
$sql="insert into test (id,name,sex) values ('','$_POST[name]','$_POST[sex ]')";
mysql_query($sql); echo "Success! ";
}
?>
Where was the previous error? $_POST['submit'] $_POST[name] Remember to capitalize it~~~
Is this the syntax? Strange. Just remember it first. You will understand later.
Note: 1.$_POST[] must be capitalized. No matter where.
2. The submit button must write name and value.name="submit" value = “ ”
3. The action must be submitted to the php file
4. Solve the problem of Chinese garbled characters on the page: in the head Write and delete
, and add
http://www.bkjia.com/PHPjc/323190.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323190.htmlTechArticleRecord it here, don’t fall down in the same place in the future! The database is bbs and the table is test. The three fields are id, name and sex. The id is auto_increment. PHP file co...