PHP在浏览器里面不能显示Mysql的数据,显示空白,display-errors为on没错 10
PHP在浏览器里面不能显示Mysql的数据,显示空白,display-errors=on没错,请高手指点错在哪里。下面是php代码<!DOCTYPEHTMLPUBLIC"...
PHP在浏览器里面不能显示Mysql的数据,显示空白,display-errors=on没错,请高手指点错在哪里。下面是php代码
<!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>
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>
php存入Mysql没问题,读取不行 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询