gpt4 book ai didi

php - string(49) "select * from php mysql 错误

转载 作者:行者123 更新时间:2023-11-29 04:38:06 26 4
gpt4 key购买 nike

我正在制作一个网页,该网页旨在显示数据库中的数据。数据库存储在 MySQL 中,我正在用 PHP 制作网页。我的 PHP 代码是

<form action="list_projects.php" method="post">
<p>Choose Search Type: <br /></p>
<select name="searchtype">
<option value="partNo">Part Number</option>
<option value="pname">Part Name</option>
<option value="color">Part Colour</option>
<option value="weight">Part Weight</option>
<option value="city">City</option>
</select>
<br />
<p>Enter Search Term: </p>
<br />
<input name="searchterm" type="text" size="20"/>
<br />
<input type="submit" name="submit" value="Search"/>
</form>

<?php
$searchtype=$_POST['searchtype'];
$searchterm=trim($_POST['searchterm']);
if (!$searchtype || !$searchterm) {
echo 'No search details. Go back and try again.';
exit;
}

$query = "select * from project where ".$searchtype." like '%".$searchterm."%'";
var_dump($query);

$result = mysqli_query($link,$query);
$num_results = mysqli_num_rows($result);

echo "<p>Number of projects found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++) {
$row = mysqli_fetch_assoc($result);
echo "<p><strong>".($i+1).". Part Number: ";
echo htmlspecialchars(stripslashes($row['partNo']));
echo "</strong><br />Part Name: ";
echo stripslashes($row['pname']);
echo "<br />Part Colour: ";
echo stripslashes($row['color']);
echo "<br />Part Weight: ";
echo stripslashes($row['weight']);
echo "<br />City";
echo stripcslashes($row['city']);
echo "</p>";
}
mysqli_free_result($result);
mysqli_close($link);
?>

但是当我运行它时,我得到 string(49) "select * from project where projectNo like '%J1%'"Number of projects found: This PHP脚本旨在加载数据库中的不同项目,并在调用此脚本的 welcome.php 脚本中加载连接到数据库并且它确实正确连接到数据库。

最佳答案

看起来您 var dumped 了错误的变量。你可以试试这个:

$query = "SELECT * FROM project WHERE ".$searchtype." LIKE '%".$searchterm."%'";

$result = mysqli_query($link,$query) or die("Line ".__LINE__." Error found: ".mysqli_error($link)); // If there's an error, it should show here.

关于php - string(49) "select * from php mysql 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36532831/

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