我試圖打開從數據庫中包含的URL,但得到的錯誤採取了網址像PHP代碼從SQL數據庫的查詢結果
Catchable fatal error: Object of class mysqli_result could not be converted to string in D:\xampp\htdocs\randomizer\index.php on line 23
我的PHP程序
<?php
$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = '#####';
$dbname = 'random';
$conn= mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
if (mysqli_connect_errno($conn))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_select_db($conn,'random') or die ("no database");
$query=mysqli_query($conn,"SELECT url FROM ufc
ORDER BY RAND()
LIMIT 1");
echo '<a href="javascript: void(0)" onclick="window.open(' . '\'' . $query . '\'' . ');">YYAAY</a>';
}
?>
用戶有沒有得到你問的解決方案? –
標記的答案只是你的問題'php代碼打開來自sql數據庫的查詢結果的URL的一半部分答案,並且它仍然被標記。在再次詢問後,他沒有給你任何解決方案。怎麼了? –