当前位置:Gxlcms > PHP教程 > 小弟我从网上下载了一个留言板的PHP代码,可是浏览器中不能显示Mysql内容

小弟我从网上下载了一个留言板的PHP代码,可是浏览器中不能显示Mysql内容

时间:2021-07-01 10:21:17 帮助过:2人阅读

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

下面是原代码






无标题文档



$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 "
&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 '姓名: ' . $name . '
邮箱: ' . $email . '
留言: ' . $comments . '
日期: ' . $time . '

';
$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;
}
?>




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

人气教程排行