2017-09-22 139 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); 

注:虽然你仍然可以在理论上连接,但你只是不能查询任何东西。这就是开发测试期间错误检查很重要的地方。

相关问题