我想通過在mysqli中使用唯一的urlvalue進行搜索來從數據庫中獲取信息,並且它不會讓我收到錯誤,因爲每次我嘗試回顯最近收到的結果時都無法將對象轉換爲字符串添加查詢。PHP&MySqli被賦予一個布爾值並且不能轉換?
PHP code;
<?php // Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$search = $_SESSION['searchby'];
// Escape the data to prevent SQL injections
$search = mysqli_real_escape_string ($conn , $search);
$query = "SELECT `urlvalue` FROM `customcountdowns` WHERE `urlvalue` ='$search' ";
$result = mysqli_query($conn, $query);
if(!$result) {
echo 'No results found.';
} else {
echo "<h1 style='padding-top: 200px';> {$search} </h1>";
while ($row = mysqli_fetch_assoc($result)) {
echo $row[`urlvalue`] . "<br>";
}
}
?>
添加的所有更改,並沒有得到一個錯誤,但在所有還沒有呼應結果接收上排20這是回聲$行[urlvalue
]的錯誤
未定義指數。 「
」;
注意 - 編輯,以顯示新的錯誤
請說明您確定在$ result變量中存在結果集嗎? –
告訴我們你的錯誤 – Edwin
[Little Bobby](http://bobby-tables.com/)說*** [你的腳本存在SQL注入攻擊風險。](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql -injection-in-php)***瞭解[MySQLi](http:// http:// http://my.wikipedia.org/wiki/Prepared_statement) php.net/manual/en/mysqli.quickstart.prepared-statements.php)。即使[轉義字符串](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)是不安全的! –