从
我尝试使用位于我的主页 - index.php 中的此表单中的数据。
<center>
<form action="search.php" method="post">
<input type="text" name="search" size="30" />
<select name='wheretosearch'>
<option value='Articles'>Articles</option>
<option value='Users'>Members</option>
</select>
<input type="submit" value="Search" />
</form>
</center>
这是 search.php 代码的主要部分:
include "all/config.php";
$search = $_REQUEST['search']; //Getting the words
$split = split(" ",$search); //If there is more than one I spit them.
foreach ($split as $array => $value)
{ $NewResult .= $value;
}
$wheretosearch = $_POST['wheretosearch'];
if ($wheretosearch = 'Articles')
{$Results = mysql_query("SELECT * FROM bgarticles WHERE title LIKE '%$value%' OR description LIKE '%$value%' OR text LIKE '%$value%' OR tags LIKE '%$value%' OR date LIKE '%$value%' OR author LIKE '%$value%' OR ip LIKE '%$value%' ");
while($row = mysql_fetch_array($Results))
{
echo "<div class='top'>";
echo "<span class='title'>";
echo "<a href=details.php?id=$row[id]>";
echo $row['title'];
echo "</a>";
echo "</span> <br><br>";
echo "<span class='author'>";
echo $row['author'];
echo "</span>";
echo "<span class='date'> Date: ";
echo $row['date'];
echo "</span> <br><br><br>";
echo "<br><br></div>" ;
echo "<div class='bottom'><br><br></div>";
}
}
if ($wheretosearch = 'members')
{$Results2 = mysql_query("SELECT * FROM members WHERE username LIKE '%$value%' OR firstname LIKE '%$value%' OR lastname LIKE '%$value%' ");
while($row2 = mysql_fetch_array($Results2))
{
echo "<div class='top'>";
echo "<span class='title'>";
echo "<a href=details.php?id=$row2[id]>";
echo $row2['username'];
echo "</a>";
echo "</span> <br><br>";
echo "<span class='author'>";
echo $row2['firstname'];
echo "</span>";
echo "<span class='date'> Date: ";
echo $row2['date'];
echo "</span> <br><br><br>";
echo "<br><br></div>" ;
echo "<div class='bottom'><br><br></div>";
}
}
无论我做什么,它总是显示来自两个 mysql 表的数据。为什么?
I tried to use the data from this form which is located in my main page - index.php.
<center>
<form action="search.php" method="post">
<input type="text" name="search" size="30" />
<select name='wheretosearch'>
<option value='Articles'>Articles</option>
<option value='Users'>Members</option>
</select>
<input type="submit" value="Search" />
</form>
</center>
This is the main part of search.php code:
include "all/config.php";
$search = $_REQUEST['search']; //Getting the words
$split = split(" ",$search); //If there is more than one I spit them.
foreach ($split as $array => $value)
{ $NewResult .= $value;
}
$wheretosearch = $_POST['wheretosearch'];
if ($wheretosearch = 'Articles')
{$Results = mysql_query("SELECT * FROM bgarticles WHERE title LIKE '%$value%' OR description LIKE '%$value%' OR text LIKE '%$value%' OR tags LIKE '%$value%' OR date LIKE '%$value%' OR author LIKE '%$value%' OR ip LIKE '%$value%' ");
while($row = mysql_fetch_array($Results))
{
echo "<div class='top'>";
echo "<span class='title'>";
echo "<a href=details.php?id=$row[id]>";
echo $row['title'];
echo "</a>";
echo "</span> <br><br>";
echo "<span class='author'>";
echo $row['author'];
echo "</span>";
echo "<span class='date'> Date: ";
echo $row['date'];
echo "</span> <br><br><br>";
echo "<br><br></div>" ;
echo "<div class='bottom'><br><br></div>";
}
}
if ($wheretosearch = 'members')
{$Results2 = mysql_query("SELECT * FROM members WHERE username LIKE '%$value%' OR firstname LIKE '%$value%' OR lastname LIKE '%$value%' ");
while($row2 = mysql_fetch_array($Results2))
{
echo "<div class='top'>";
echo "<span class='title'>";
echo "<a href=details.php?id=$row2[id]>";
echo $row2['username'];
echo "</a>";
echo "</span> <br><br>";
echo "<span class='author'>";
echo $row2['firstname'];
echo "</span>";
echo "<span class='date'> Date: ";
echo $row2['date'];
echo "</span> <br><br><br>";
echo "<br><br></div>" ;
echo "<div class='bottom'><br><br></div>";
}
}
No matter I do it always shows data from both mysql tables. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您使用一个等号来设置一个变量。双等于进行比较。
You're using a single equals sign, which sets a variable. A double equals compares.
在
if
语句中使用==
而不是=
。Use
==
instead of=
in yourif
statements.=
!===
您的 if 条件包含赋值操作,而不是比较操作。
这是常见的错误,很多博客都包含避免这种错误的简单方法。
=
!===
Your if conditions contain assignments, not comparison operations.
Common mistake, plenty of blogs contain easy ways to avoid it.
老实说:http://bobby-tables.com/
(然后检查您的
if
-子句,您使用的是赋值 (=) 而不是比较 (==))Honestly: http://bobby-tables.com/
(and then check your
if
-clauses, you're using assignments (=) instead of comparisons (==))您缺少一个等号,因此它正在进行分配而不是测试相等性。
应该是......
另外:你没有逃避你的查询,所以你的数据库很容易被黑客攻击。在查询中使用变量之前,请像这样转义它们:
You're missing an equal sign, so it's making an assignment instead of testing for equality.
should be...
Also: you're not escaping your queries, so your database would be easily hackable. Before using your variables in a query, escape them like so: