小弟我從網上下載了一個留言板的PHP代碼,可是瀏覽器中不能顯示Mysql內容
來源:互聯網
上載者:User
求教:我從網上下載了一個留言板的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;
}
?>
------解決方案--------------------
其實就是錯了,只是你錯誤模式沒有開而已,你開啟錯誤模式後再看看。