我觉得我只需要另外一套眼睛。当然,数据库中有一些东西需要搜索,但是没有显示任何内容。语法或逻辑是否有问题。这是一个文件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>
答案 0 :(得分:3)
您的表单正在使用post方法,并且您正在尝试通过$ _GET
获取值而不是:
$clean = msql_real_escape_string($_GET['value']);
使用此:
$clean = msql_real_escape_string($_POST['value']);
或者
$clean = msql_real_escape_string($title);
答案 1 :(得分:0)
要在mysql中搜索,你应该使用LIKE。如果你想搜索字符串中的任何地方,你应该用%封装。例如:
$run = mysql_query("SELECT * FROM db WHERE name LIKE '%$clean%'") or die(mysql_error());
了解更多信息:http://dev.mysql.com/doc/refman/5.7/en/string-comparison-functions.html