復制代碼 代碼如下:
<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();
?>