【发布时间】:2015-12-22 15:12:09
【问题描述】:
我觉得我只需要另一双眼睛。数据库中当然有要搜索的内容,但没有显示任何内容。语法或逻辑是否有问题。这一切都在一个文件中 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 值,因为你同时使用了它们
-
代替$_GET,你应该使用$_POST
-
改变这个 $clean = msql_real_escape_string($_GET['value']);到 $clean = msql_real_escape_string($title);
-
您是否创建了
msql_real_escape_string?你在检查你的错误日志吗?当您说nothing is displayed时,您的意思是您得到的是空白页还是没有搜索结果?
标签: php mysql database function search