I am trying to make a url shortening website. However, I am running into this error when I try clicking the submit input: Fatal error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\index.php. I've seen others having this issue but never managed to fix it. Thanks in advance!
<?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>
As I stated in comments, you didn't choose a database.
As requested:
This line:
Should have read as:
and replacing "database" with the name of your database.
The documentation can be found at the following address on PHP.net:
Example pulled from the manual along with error checking:
Note: Alhough you can still theoretically connect, you just wouldn't be able to query anything though. That's where error checking is important during development testing.