2017-07-29 33 views
-2

我的網站上有一個處理消息和警報通知系統的腳本。該腳本從MySQL數據庫中提取數據,並且它在本地就像一個魅力一樣,但在我的現場網站上,查詢失敗。這個腳本總是返回false並進入else條件,但是在本地它的工作方式與它應該完全相同。我的PHP和MySQL腳本在本地完美運行,但不在我的現場網站

$queryNots = 'Select message, DATE_FORMAT(timeSent, "%h:%i %p %W, %M %D ") timeSent FROM notifications WHERE UserID="' . $userId . '" AND seen="n";'; 
if ($result = $con->query ($query)) { 
    $resultNum = mysqli_num_rows ($result); 
    echo '<h2>You have ' . $resultNum . ' Notifications</h2> 
      <ul>'; 
    while ($row = $result->fetch_assoc()) { 
     echo '<li>' . $row ["message"] . ' @ ' . $row ['timeSent'] . '</li>'; 
    } 
    if ($resultNum > 0) { 
     echo ' 
      </ul> 
       <form method="post" action="deleteNots.php"> 
        <input type="hidden" name="curID" value="' . $userId . '"> 
        <input type="submit" value="Dismiss"> 
       </form> 
      '; 
    } 
} else { 
    echo '<h2>Error reading table</h2>'; 
} 

在直播現場,如果我拿出的if-else,只是運行查詢,它不僅失敗了,它殺死了整個腳本。我不知道可能是什麼原因造成的,我知道表格是一樣的,因爲我在不同的腳本中使用它們就好了。

我絕對沒有什麼可以使用的,因爲它沒有給我任何類型的MySQL錯誤消息。我真的很想弄明白,因爲我希望儘快讓這個網站恢復正常工作。

+3

嘗試回顯mysql_error()看看發生了什麼 – handsome

+0

初始化'$ con'後,你可以'var_dump($ con)'顯示一些東西嗎?也不應該是'$ con> query($ queryNots)'? – caramba

+0

'seen =「n」;';'... ???這是什麼 ?在你的查詢記錄中..爲什麼使用兩個分號? –

回答

0
$query = 'Select message, DATE_FORMAT(timeSent, "%h:%i %p %W, %M %D ") timeSent FROM notifications WHERE UserID="' . $userId . '" AND seen="n"'; 


$result = $con->query($query); 

if ($result) { 

    $resultNum = mysqli_num_rows($result); 
    echo '<h2>You have '.$resultNum.'Notifications</h2><ul>'; 

    while($row = $result->fetch_assoc()) { 

     echo '<li>' . $row ["message"] . ' @ ' . $row ['timeSent'] . '</li>'; 
    } 

    if ($resultNum > 0) { 
     echo ' 
      </ul> 
       <form method="post" action="deleteNots.php"> 
        <input type="hidden" name="curID" value="' . $userId . '"> 
        <input type="submit" value="Dismiss"> 
       </form> 
      '; 
    } 
} else { 
    echo '<h2>Error reading table</h2>'; 
} 

注:

  • 更改$queryNots變量,因爲你用下面的代碼 即$query變量:$result = $con->query($query);
  • 不必要的分號;在$queryNots :: seen="n";';
  • ()
+0

答案應該有一個解釋,不只是'試試這個'。 – chris85

+0

'queryuNote'沒有被使用,它的aciousally使用查詢和'unwanterd'分號代碼中使用改變.. @ chris85 –

+1

Rishi,請在你的答案中提及它。 –

相關問題