gpt4 book ai didi

php - 将 MySQL 服务器转移到 php 页面 = 查询不起作用?

转载 作者:行者123 更新时间:2023-11-30 00:21:58 25 4
gpt4 key购买 nike

我试图制作一个显示 MySQL 搜索引擎的 php 页面,它在一台服务器上运行:但是,该服务器崩溃了,我被迫重新启动它。即使我使用相同的代码,搜索引擎也不再工作 - 我的代码如下:

<html>
<head>
<meta charset="UTF-8">

<title>Search Engine Test</title>
<h1>Gromax</h1>

</head>
<body>
<form action="search1.php" method="post">
<input type="text" name="keyword">
<input type="submit" name="search" value="Search">
<br>
<br>
</form>


<script language="php">
// Create a database connection
error_reporting(0);

$connection = mysql_connect("localhost", "$ mysql -u anonymous", "");
if (!$connection) {
die("Please reload page. Database connection failed: " . mysql_error());
}

// Select a databse to use
$db_select = mysql_select_db("test", $connection);
if (!$db_select) {
die("Please reload page. Database selection failed: " . mysql_error());
}

// Search Engine
// Only execute when button is pressed
if (isset($_POST['keyword'])) {
// Filter
$keyword = trim($_POST['keyword']);

// Select statement
$search = "SELECT Price FROM table_1 WHERE Model = '$keyword'";

// Display
$result = mysql_query($search) or die('query did not work');

while ($result_array = mysql_fetch_array($result)) {
$arrlength=count($result_array);
for($x=0;$x+1<$arrlength;$x++){

echo "Price: " . $result_array[$x];
echo "<br>";

}
}


}
?>




</script>


</body>
</html>

如有任何帮助,我们将不胜感激。

最佳答案

我非常确定您的查询或数据库连接中有错误。尝试评论该行:

// error_reporting(0);

看看你得到了什么错误......

关于php - 将 MySQL 服务器转移到 php 页面 = 查询不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23161988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com