我的链接缩短器出现 MySQL/MySQLi/PHP 错误,错误是:
Fatal error: Call to a member function bind_param() on a non-object in
/home/exabit/public_html/9ui/index.php on line 50
这是有问题的行。
$reslove->bind_param("ss",$link, $short_url);
这是其余的代码
<?php
$data_base = new mysqli ("http://host38.qnop.net/~exab","exab_ml","MKnOz3A]h~aw","exab_ml");
function generateRandomString($length = 3) {
$key = 'abcdefghijklmnopqrstuvwxyz1234567890';
$keyLength = strlen($key);
$string = '';
for ($i = 0; $i < $length; $i++) {
$string .= $key[rand(0, $keyLength - 1)];
}
return $string;
}
if (isset($_GET['title'])) {
$reslove = $data_base->prepare("SELECT * FROM links WHERE title=?");
$reslove->bind_param("s", $_GET['title']);
$reslove->execute();
$goto = $reslove->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'];
$reslove = $data_base->prepare("INSERT INTO links VALUES('',?,?)");
$reslove->bind_param("ss",$link, $short_url);
$reslove->execute();
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<center>
<form>
<p style="color:#05ff19;font-family:Tahoma;font-size:16px;text-align:center">Shortened Link: </p><input id=shortenedurl style="background-color:#000;color:#05ff19;font-family:Tahoma;font-size:16px;vertical-align:middle;border:1px solid #05ff19" type="text" value=<?php echo "9ui.co/$short_url";}?>'>
</form>
</center>
resolve 的拼写错误与此无关。
在此先感谢,
扎克戴维斯