小弟我從網上下載了一個留言板的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;
}
?>




------解決方案--------------------
其實就是錯了,只是你錯誤模式沒有開而已,你開啟錯誤模式後再看看。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.