-2
我刚刚开始使用PHP,需要MySQL中简单代码的帮助,我认为我需要它在MySQLi中,因为我得到一个错误 我已经将PHP代码更改为下面和现在收到以下错误:MySQL到MySQLi转换
!) Notice: Use of undefined constant searchengine - assumed 'searchengine' in C:\wamp\www\search\results.php on line 6
Call Stack
# Time Memory Function Location
1 0.0004 242504 {main}() ...\results.php:0
索引页
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Helpy Search Engine</title>
</head>
<body>
<h1>Go ahead, search.</h1>
<form action="results.php" method="get">
<input type="text" name="query" placeholder="Search..">
<button type="submit">Search</button>
</form>
</body>
</html>
<?php
$search = $_GET['query'];
($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "root", "")) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . searchengine));
$query = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM results WHERE title LIKE '%".$search."%'");
if(mysqli_num_rows($query) >= 1) {
while($a = mysqli_fetch_array($query)) {
echo "<a href='".$a['url']."'>".$a['title']."</a><p>".$a['description']."</p><hr/>";
}
} else {
echo "Oh no! Nothing was found.";
}
?>
你没有尝试过什么吗?有你知道的手册 –
在阅读了一些更多的手册后,我已经更新了我的代码,如上所述。 – Bill04
此代码中存在SQL注入漏洞,请在上线前修复此问题!搜索“SQL注入MySQLi”以了解更多信息。 – halfer