2013-11-27 20 views
0

由於某種原因,當我在其中有以下php代碼時,我的頁面無法加載......但是當我在我的編輯器中驗證SQL語句時,它返回結果(1行)精細。我試着用F12 Chrome的東西進行調試,但控制檯不顯示任何錯誤,除了一些CSS的東西。我不知道如何在更遠的程度上使用它。PHP頁面未加載SQL語句包括

有沒有初步的想法?

頁: http://www.runic-paradise.com/editinfo.php

殺死的頁面時,它的存在代碼:

// GET NEWS FROM DB 
$result = $mysqli->query("SELECT Content, Reference FROM site WHERE Reference='Rules'"); 

周邊 代碼:

 <form id="newsform" name="newsform" action="editinfo.php?step=2" method="post" enctype="multipart/form-data"> 
     <h4>Server Rules</h4> 
     <textarea class="editor" rows="4" style="width:50%;" name="Content" id="postbody"> 
<?php 
//UPDATE DB IF NECESSARY 
if($_GET['step'] == 2) { 
    $mysqli->query("UPDATE site SET Content='$_POST[Content]' WHERE Reference='Rules'"); 
} 
// GET NEWS FROM DB 
$result = $mysqli->query("SELECT Content, Reference FROM site WHERE Reference='Rules'"); 
var_dump($mysqli->error); 
echo $result['Content']; 
$mysqli->close(); 

?> 
     </textarea> 

     <!-- hidden inputs --> 
     <input type="hidden" id="x" name="x" /> 
     <input type="hidden" id="y" name="y" /> 
     <input type="hidden" id="w" name="w" /> 
     <input type="hidden" id="h" name="h" /> 

     <input type="hidden" name="step" value="2"> 
     <br><br> 
     <input type="submit"> 
     </form> 
+2

嘗試將'error_reporting(E_ALL);'放在php頁面的頂部並重新運行。 – asprin

+2

使用mysqli_error()查看造成錯誤的原因 – rakimo

+2

頁面的源代碼聲明此錯誤致命錯誤無法將類型爲mysqli_result的對象用作/home/content/60/11957760/html/runicparadise/editinfo中的數組.php on line ' – asprin

回答

3

你是不是提取數據正確。

$result = $mysqli->query("SELECT Content, Reference FROM site WHERE Reference='Rules'"); 
$result = $result->fetch_assoc(); // <-- here 
echo $result['Content']; 

您需要檢索結果作爲數組,然後才能將結果視爲數組。

1

它不是保護,任何SQL注入醜陋的代碼。不要直接將用戶輸入數據傳遞給SQL。

可能是錯誤的:

<b>Fatal error</b>: Cannot use object of type mysqli_result as array in <b>/home/content/60/11957760/html/runicparadise/editinfo.php</b> on line <b>117</b><br /> 
+1

謝謝:)已更新我的更新爲$內容= $ mysqli-> real_escape_string($ _ POST ['內容']); \t $ mysqli-> query(「UPDATE site SET Content ='$ contents'WHERE Reference ='Rules'」); – runelynx

+1

這樣比較好,但我建議你使用[預備聲明](http://php.net/manual/en/mysqli.prepare.php)。 –