Database ERROR: No Database Selected ??
BJade 2004-03-27 10:53:54 <html>
<head>
<title>Delete from Staff where StaffNo = "?" </title>
</head>
<body bgcolor="ffffff">
<h2> Rows in Staff table </h2>
<p>
<table border="1" width="100%">
<tr>
<td width="10%" align="center"><big><strong>staffNO</strong></big></td>
<td width="20%" align="center"><big><strong>staffName</strong></big></td>
<td width="20%" align="center"><big><strong>comission</strong></big></td>
<td width="20%" align="center"><big><strong>position </strong></big></td>
<td width="20%" align="center"><big><strong>branchNO</strong></big></td>
<td width="20%" align="center"><big><strong>month</strong></big></td>
<td width="15%" align="center"><big><strong>numberOftasks</strong></big></td> </tr>
</table>
<?php
$mysql_link = mysql_connect("localhost", "root", "monday")
or die("Could not connect");
mysql_select_db("mysqldb") or die("Could not select database");
$query = "SELECT * FROM staff";
$mysql_result = mysql_query($query) or die("Query failed");
print "<table>\n";
while ($line = mysql_fetch_array($mysql_result, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
print "<td width=\"16%\">$col_value</td>";
}
print "<tr>\n";
}
print "</table>\n";
mysql_free_result($mysql_result);
mysql_close($mysql_link);
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$StaffNo = addslashes($_POST["StaffNo"]);
$sql = " DELETE FROM Staff ";
$sql .= " WHERE StaffNo = '$StaffNo' ";
$result = mysql_query($sql);
if (mysql_error())
{
print "Database ERROR: " . mysql_error();
}
else
{
$query="select * from staff";
$mysql_result = mysql_query ($query);
if ( mysql_num_rows ($mysql_result)>0)
{
print "<p>";
print "<table border=\"1\" width=\"100%\">";
print "<tr>";
print "<td width=\"10%\" align=\"center\"><big><strong>StaffNo</strong></big></td>";
print "<td width=\"30%\" align=\"center\"><big><strong>StaffName</strong></big></td>";
print "<td width=\"30%\" align=\"center\"><big><strong>StaffContact</strong></big></td>";
print "<td width=\"30%\" align=\"center\"><big><strong>StaffSalary</strong></big></td>";
print "<td width=\"10%\" align=\"center\"><big><strong>StaffCommission</strong></big></td>";
print "<td width=\"30%\" align=\"center\"><big><strong>Month</strong></big></td>";
print "<td width=\"30%\" align=\"center\"><big><strong>NumberOfSalesAndRentals</strong></big></td>";
print "<td width=\"30%\" align=\"center\"><big><strong>BranchNo</strong></big></td>";
print "</tr>";
print "</table>";
while ($line = mysql_fetch_array($mysql_result, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
print "<td width=\"16%\">$col_value</td>";
}
print "<tr>\n";
}
print "</table>\n";
mysql_free_result($mysql_result);
mysql_close($mysql_link);
}
print "<p><b>Row deleted from Staff table.</b></p>\n";
}
}
?>
<form name="fa" action="test1.php" method="POST">
<b>Staff No: </b> <input type="text" name="StaffNo" size=10>
<th colspan=2><p><input type="submit" value="Delete Row"></p></th>
</form>
</body>
</html>
运行http://localhost/test1.php后,显示Database ERROR: No Database Selected ,为什么??