我試圖使用位於我的主頁 - index.php中的此表單中的數據。使用PHP從<select>標記中收集數據
<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的表中的數據。爲什麼?
*(相關)* [我應該更改$ _REQUEST到$ _POST](http://stackoverflow.com/questions/2987447/should-i-change-request-to-post/2987468#2987468) – Gordon 2011-02-28 19:33:59