<html>
<head>
<title>插入一條新數(shù)據(jù)</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="重設(shè)"></td>
</tr>
</table>
</form>
</body>
</html>
復(fù)制代碼 代碼如下:
<?php
@mysql_connect("localhost", "root","1981427") //選擇數(shù)據(jù)庫之前需要先連接數(shù)據(jù)庫服務(wù)器
or die("數(shù)據(jù)庫服務(wù)器連接失敗");
@mysql_select_db("test") //選擇數(shù)據(jù)庫mydb
or die("數(shù)據(jù)庫不存在或不可用");
$id = $_POST['id'];
$username = $_POST['username'];
$password = $_POST['password'];
$query = mysql_query("insert into tablename1 values($id, '$username', '$password')");
if($query)
echo "數(shù)據(jù)插入成功";
else
echo "數(shù)據(jù)插入失敗";
mysql_close();
?>
php技術(shù):php 動態(tài)添加記錄,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。