2017-09-22 84 views
1

我試圖使網址縮短網站。然而,當我嘗試點擊提交輸入時,我遇到了這個錯誤: 致命錯誤:調用成員函數bind_param()在布爾中的C:\ xampp \ htdocs \ index.php我見過其他人有這個問題,但從來沒有設法解決它。 在此先感謝!致命錯誤:在C: xampp htdocs index.php中的布爾值中調用成員函數bind_param()

<?php 

$db = new mysqli("localhost","root",""); 

if (isset($_POST['shorten'])) { 
//echo "Clicked"; 
$result = $db->prepare("INSERT INTO links VALUES('',?,'test')"); 
$result->bind_param('s', $_POST['url_to_shorten']); 
$result->execute(); 
echo "Done."; 
} 

?> 
<!doctype html> 
<html> 
<head> 
<title>Orix.ml - free link shortener</title> 
</head> 
<body> 
<center> 
<h1>ORIX.ML</h1> 
<h2>FREE USB SHORTENING SERVICE</h2> 
<form action="/" method="POST"> 
<input type="text" name="url_to_shorten" value="" placeholder="PASTE YOUR LINK HERE"> 
<input type="submit" name="shorten" value="GO"> 
</form> 
</center> 
</body> 
</html> 
+2

簡單;你沒有選擇一個數據庫。 –

+0

如果你看到其他人有這個問題,你有沒有看到使用'echo $ db->錯誤的建議;'看到錯誤的原因? – Barmar

+0

當我說我很笨,我很愚蠢。謝謝,@ Fred-ii-,並請將其作爲答案發布,以便我可以將其選爲最佳答案。 – DimitarTheN00b

回答

2

正如我在評論中所述,您並未選擇數據庫。

按照要求:

這條線:

$db = new mysqli("localhost","root",""); 

本來應該讀作:

$db = new mysqli("localhost","root","", "database"); 

,並與你的數據庫的名稱替換 「數據庫」。

的文檔可以在以下網址找到上PHP.net:

實施例從手動拉動錯誤檢查沿着:

<?php 
$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db"); 

if (!$link) { 
    echo "Error: Unable to connect to MySQL." . PHP_EOL; 
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; 
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; 
    exit; 
} 

echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL; 
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL; 

mysqli_close($link); 

注:雖然你仍然可以在理論上連接,但你只是不能查詢任何東西。這就是開發測試期間錯誤檢查很重要的地方。

相關問題