我觉得我只需要另一双眼睛来看待这个问题。数据库中当然有一些东西可以搜索,但是什么也没有显示。语法或逻辑有问题吗?这一切都在一个文件 index.php 中
<form action = "index.php" method = "post">
Search: <input type="text" name="value" placeholder="Is it part of the FWO?"></input>
<input type=submit name = "search" value="Search">
</form>
<a href="LINKY">New Entry</a>
<br>
<p>Search Results</p>
<hr />
<?php
error_reporting(E_ALL);
$title = $_POST['value'];
echo "You have searched: " .$title;
echo "<br>";
$con = mysql_connect("localhost", "user", "pass") or die ('Could not connect, this is the error: ' . mysql_error());
mysql_select_db("db") or die ('Sorry could not access database at this time. This is the error: ' . mysql_error());
$clean = msql_real_escape_string($_GET['value']);
echo "Another test ". $clean;
$run = mysql_query("SELECT * FROM db WHERE name = '$clean'") or die(mysql_error());
if(mysql_num_rows($run) >= 1){
echo "found entry";
while($i = mysql_fetch_array($run)){
echo $i['creator'];
}
}
else {
echo "No entries found";
}
mysql_close($con);
?>
</body>
</html>
最佳答案
您的表单正在使用 post 方法,您正在尝试通过 $_GET 获取值
而不是这个:
$clean = msql_real_escape_string($_GET['value']);
使用这个:
$clean = msql_real_escape_string($_POST['value']);
或者
$clean = msql_real_escape_string($title);
关于php/mysql搜索功能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34418863/