php 动态添加记录
<html>
<head>
<title>插入一条新数据</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form method="post" name="form1" action="insert.php">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">编号:</td>
<td><input type="text" name="id" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">用户名:</td>
<td><input type="text" name="username" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">密码:</td>
<td><input type="text" name="password" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td colspan="2" nowrap><input name="Submit" type="submit" value="提交">
<input type="reset" name="Reset" value="重设"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
@mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器
or die("数据库服务器连接失败");
@mysql_select_db("test") //选择数据库mydb
or die("数据库不存在或不可用");
$id = $_POST['id'];
$username = $_POST['username'];
$password = $_POST['password'];
$query = mysql_query("insert into tablename1 values($id, '$username', '$password')");
if($query)
echo "数据插入成功";
else
echo "数据插入失败";
mysql_close();
?>