由 ministerwuxi 在 08-16-2003 20:24 发表:
表单的数据插入不到数据库
表单的数据插入不到数据库
//database mydb
//table employees
CREATE TABLE employees ( id tinyint(4) DEFAULT '0' NOT NULL
AUTO_INCREMENT, first varchar(20), last varchar(20),
address varchar(255), position varchar(50), PRIMARY KEY (id),
UNIQUE id (id));
//tt.html
1<html>
2<body>
3<form action="tt.php" method="post">
4
5
6
7名:<input name="first" type="Text"/><br/>
8
9
10
11姓:<input name="last" type="Text"/><br/>
12
13
14
15住址:<input name="address" type="Text"/><br/>
16
17
18
19职位:<input name="position" type="Text"/><br/>
20<input name="submit" type="Submit" value="输入信息"/>
21</form>
22</body>
23</html>
//tt.php
1
2
3$db = mysql_connect("localhost", "root");
4
5
6
7mysql_select_db("mydb",$db);
8
9
10
11$sql = "INSERT INTO employees (first,last,address,position)
12
13VALUES ('$first','$last','$address','$position')";
14
15
16
17$result = mysql_query($sql);
18
19
20
21echo "Thank you! Information entered.\n";
22
23
24
结果是id插入到数据库中
而其他都