日期:2014-05-17  浏览次数:20447 次

求教:我从网上下载了一个留言板的PHP代码,可是浏览器中不能显示Mysql内容
我从网上下载了一个留言板的PHP代码,可是在浏览器中不能显示Mysql表里的内容,没有显示错误,就是空白,不知道是哪部分代码错误,请有经验的朋友帮我看看,谢谢。 

下面是原代码 


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>无标题文档</title> 
</head> 

<body> 
<?php 
$DBhost = "localhost"; // 服务器名字 
$DBuser = "用户名(已有)"; // 用户名 
$DBpass = "密码(已有)"; // 用户密碼 
$DBName = "super-tomato"; //资料库名字 
$table = "guestbook"; // 资料库的table名 
$numComments = 10; // 每頁所显示的笔数 

//开始连接mysql 
$DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("无法连接资料库: " . mysql_error()); 
//选择mysql资料库 
mysql_select_db($DBName, $DBConn) or die("无法连接资料库: " . mysql_error()); 

$action = $_GET['action']; //等待执行動作 

switch($action) { //這裡使用switch ....case, 我想大家不陌生吧... 在AS當中也有 
case 'read' : //读取资料 
// sql指令...选择资料表的內容 
$sql = 'SELECT * FROM `' . $table . '`'; 
$allComments = mysql_query($sql, $DBConn) or die("无法选取资料 : " . mysql_error()); 
$numallComments = mysql_num_rows($allComments); //取得返回资料的笔数 
$sql .= ' ORDER BY `time` DESC LIMIT ' . $_GET['NumLow'] . ', ' . $numComments; 
$fewComments = mysql_query($sql, $DBConn) or die("无法选取资料 : " . mysql_error()); 
$numfewComments = mysql_num_rows($fewComments); 
print '&totalEntries=' . $numallComments . '&'; 
print "<br>&entries="; 

if($numallComments == 0) { 
print "目前无任何记录...."; 
} else { 
while ($array = mysql_fetch_array($fewComments)) { 
$name = mysql_result($fewComments, $i, 'name'); 
$email = mysql_result($fewComments, $i, 'email'); 
$comments = mysql_result($fewComments, $i, 'comments'); 
$time = mysql_result($fewComments, $i, 'time'); 

print '<b>姓名: </b>' . $name . '<br><b>邮箱: </b>' . $email . '<br><b>留言: </b>' . $comments . '<br>日期: ' . $time . '<br><br>'; 
$i++; 


break; 

case 'write' : //写记录 
// 接收Flash传过来的资料 
$name = ereg_replace("&", "%26", $_POST['userName']); 
$email = ereg_replace("&", "%26", $_POST['userEmail']); 
$comments = ereg_replace("&", "%26", $_POST['userMessage']); 
$todayDate = date ("Y-m-d H:i:s",time()); // 取得目前服务器的时间 

// 把资料写入资料表內 
$sql = "INSERT INTO " . $table . " (name, email, comments, time) VALUES ('$name', '$email', '$comments', '$todayDate')"; 
$insert = mysql_query($sql, $DBConn) or die("无法连接到数据库: " . mysql_error()); 

if($insert) { 
print '$msg=Successful'; 
} else { 
print '$msg=Error'; 

break; 

?> 
</body> 
</html> 


------解决方案--------------------
其实就是错了,只是你错误模式没有开而已,你打开错误模式后再看看。