• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-25) 11次浏览 已收录 0个评论

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

下面是原代码

<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
无标题文档

<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 ‘

本文来源gao!%daima.com搞$代*!码$网3

搞代gaodaima码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;
}
?>

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


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:小弟我从网上下载了一个留言板的PHP代码,可是浏览器中不能显示Mysql内容

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址