2017-07-26 38 views
-3

文本在小區i在使用JSON estraction文件的問題:空白結果與 - 在PHP和JSON

如果在數據庫中,我有一個字段具有 - 內部結果的JSON是空

這是代碼

<?php 
$host = "****"; 
$user = "****"; 
$password = "*****"; 
$db = "****"; 
$table=$_GET['table']; 


//open connection to mysql db 
$connection = mysqli_connect($host,$user,$password,$db) or die("Error " . 
mysqli_error($connection)); 

//fetch table rows from mysql db 
$sql = "select * from ".$table.";"; 
$result = mysqli_query($connection, $sql) or die("Error in Selecting " . 
mysqli_error($connection)); 

//create an array 
$emparray = array(); 
while($row =mysqli_fetch_assoc($result)) 
{ 
    $emparray[] = $row; 
    } 
    echo json_encode($emparray); 

    //close the db connection 
    mysqli_close($connection); 
?> 

感謝 莫羅 PS的 - 是行

例如在細胞內: 敵人採取-1的攻擊檢定,並保存對...周圍表

符號不是有用:(

我所知道的是弱黑客但現在是私人:d

+4

你意識到你正在嘗試做的事情是危險的,並且有一個巨大的sql注入漏洞。 –

+1

你有$ _GET來獲取表...請改變 - 黑客會愛你的網站.. – ThisGuyHasTwoThumbs

+1

什麼'mysqli_error($連接)'和PHP的錯誤報告把你丟回來? http://php.net/manual/en/function.error-reporting.php你留下了重要的細節。 –

回答

-3

更新我從chris85

評論答案用周圍的表名反引號字符(`)對待表名作爲正確的表標識:

$sql = "select * from `".$table."`;"; 

但是;千萬不要在通過互聯網到達的網站上做這樣的事情!

+1

反引號是用於標識符,而不是字符串。分號也是反面的錯誤一面。只有在保留名稱或使用非標準字符(下劃線/字母數字)時,反引號纔是必需的。 – chris85

+0

的確,我更新了答案@ chris85 – Cagy79