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 ,为什么??
...全文
1293 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
BJade 2004-03-28
  • 打赏
  • 举报
回复
有呀:$sql = " DELETE FROM Staff ";
$sql .= " WHERE StaffNo = '$StaffNo' ";

$result = mysql_query($sql);

countstars 2004-03-28
  • 打赏
  • 举报
回复
$mysql_link = mysql_connect("localhost", "root", "monday")
or die("Could not connect");

mysql_select_db("mysqldb") or die("Could not select database");

数据库选择语句少了一个参数,改为:
mysql_select_db("mysqldb", $mysql_link) or die("Could not select database");

另外,你的很多数据库操作语句怎么没有第二个参数---连接参数呢?
hahawen 2004-03-28
  • 打赏
  • 举报
回复
数据库名美输错吗?
chinaworker 2004-03-27
  • 打赏
  • 举报
回复
你删除的时候没有指定表名?

delete from table where id=1
BJade 2004-03-27
  • 打赏
  • 举报
回复
sorry,应该时运行http://localhost/test1.php后,先会显示数据库里的所有信息,当输入需要删除的数据后,显示:Database ERROR: No Database Selected。为什么?
chinaworker 2004-03-27
  • 打赏
  • 举报
回复
mysqldb数据库不存在

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧