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