這裡簡單介紹 PHP + MySQL 的資料新增語法:
data.php
insert.php
data.php
<html>
<head>
<title>Data</title>
</head>
<body>
<form name="form1" method="post" action="insert.php">
Data1:<input type="text" name="data1">
Data2:<input type="text" name="data2">
<input type="submit" name="Submit" value="送出">
</form>
</body>
</html>
<head>
<title>Data</title>
</head>
<body>
<form name="form1" method="post" action="insert.php">
Data1:<input type="text" name="data1">
Data2:<input type="text" name="data2">
<input type="submit" name="Submit" value="送出">
</form>
</body>
</html>
insert.php
<?php
$link = mysql_connect("你的主機名稱"、"你的名稱"、"你的密碼") or die ("無法連接".mysql_error());
mysql_select_db("你的資料庫名稱"、$link) or die ("無法選擇資料庫".mysql_error());
$sql = "INSERT into 你的資料表名稱 (data1,data2) Values ('$_POST[data1]','$_POST[data2]')";
mysql_query($sql、$link) or die ("無法新增".mysql_error());
mysql_close($link);
?>
有 die 的寫法好處是,可以顯示錯誤訊息讓你知道哪裡錯了。 $link = mysql_connect("你的主機名稱"、"你的名稱"、"你的密碼") or die ("無法連接".mysql_error());
mysql_select_db("你的資料庫名稱"、$link) or die ("無法選擇資料庫".mysql_error());
$sql = "INSERT into 你的資料表名稱 (data1,data2) Values ('$_POST[data1]','$_POST[data2]')";
mysql_query($sql、$link) or die ("無法新增".mysql_error());
mysql_close($link);
?>
| 2006/01/12 18:14 |
Trackback Address :: http://blog.raienet.com/trackback/192
