[php]
<html>
<head><title>Web Database Sample Index</title>
</head>
<body bgcolor=#ffffff>
<h1>Data from mytable</h1>
<?
mysql_connect("localhost", "webuser", "");
$query = "SELECT name, phone FROM mytable";
$result = mysql_db_query("example", $query);
if ($result) {
echo "Found these entries in the database:<ul>";
while ($r = mysql_fetch_array($result)) {
$name = $r["name"];
$phone = $r["phone"];
echo "<li>$name, $phone";
}
echo "</ul>";
} else {
echo "No data.";
}
mysql_free_result($result);
?>
<p><a href="add.php3">Add new entry</a>
</body>
</html>
这是index.php的内容<html>
<head><title>Web Database Sample Inserting</title>
</head>
<body bgcolor=#ffffff>
<?
mysql_connect("localhost", "webuser", "");
if (isset($name) && isset($phone)) {
$query = "INSERT INTO mytable VALUES ('$name', '$phone')";
$result = mysql_db_query("example", $query);
if ($result) {
echo "<p>$name was added to the database</p>";
}
}
?>
<h1>Add an entry</h1>
<form>
Name: <input type=text name='name'><br>
Phone: <input type=text name='phone'><br>
<input type=submit>
</form>
<p><a href="index.php3">Back to index</a>
</body>
</html>
[/php]
这是add.php的内容