I'm hoping you can help, I'm creating a URL Shortener for a company, I've ran into an error: Call to a member function bind_param() on a non-object
, Your reply is very much appreciated.
<?php
$data_base = new mysqli ("localhost","exab_linus","HZYhVCz8bxm7NmU9","exab_lmg");
function generateRandomString($length = 4) {
$key = 'abcdefghijklmnopqrstuvwxyz1234567890';
$keyLength = strlen($key);
$string = '';
for ($i = 0; $i < $length; $i++) {
$string .= $key[rand(0, $keyLength - 1)];
}
return $string;
}
if (isset($_GET['title'])) {
$resolve = $data_base->prepare("SELECT * FROM links WHERE title=?");
$resolve->bind_param("s", $_GET['title']);
$resolve->execute();
$goto = $resolve->get_result()->fetch_array();
$goto1 = $goto[1];
header("Location: $goto1");
}
if (isset($_POST['submit'])) {
$short_url = generateRandomString();
if (!preg_match("/^(http|https):/", $_POST['long_url'])) {
$_POST['long_url'] = 'http://'.$_POST['long_url'];
}
$link = $_POST['long_url'];
$resolve = $data_base->prepare("INSERT INTO links (long_url, title) VALUES (?, ?);");
$resolve->bind_param("ss",$link, $short);
$resolve->execute();
?>
Thanks in advance, Zack