1

我目前正在编写一个 MySQL 搜索页面,但我无法弄清楚如何制作它,因此如果没有以一种形式放入数据,它将什么都不做,如果有另一种形式的数据,它'将在数据库中搜索该值。

<?PHP 
echo '<h3 class="hp-1">Kick Logs</h3><div class="wrapper">
<div class="logcol-1"><form name="form1" id="mainForm" method="post"enctype="multipart/form-data" action="' . $_SERVER['REQUEST_URI'] . '">
<input name="name" type="text" id="name" placeholder="Players Name"> 
</form>';
echo '<form name="form2" id="mainForm" method="post"enctype="multipart/form-data" action="' . $_SERVER['REQUEST_URI'] . '"><input name="reason" type="text" id="reason" placeholder="Kick Reason"></form>';
$name = mysql_real_escape_string($name);
$reason = mysql_real_escape_string($reason);

$kicklogname = mysql_query("SELECT * FROM `log1` WHERE `user` LIKE '%$name%'") or die(mysql_error());
$kicklogreason = mysql_query("SELECT * FROM `log1` WHERE `user` LIKE '%$reason%'") or die(mysql_error());
if($name == ""){
echo "You must enter a name to search"; }
else {
    echo '<table width="700" border="0">
        <tr class="listheader">
        <td width="100" bgcolor="#afe6ff">Username</td>
        <td width="220" bgcolor="#afe6ff">Reason</td>
    </tr>';
    while($row = mysql_fetch_array($kicklogname))
    {
        echo '<tr><td bgcolor="#daf4ff" class="contentleft">';
        echo $row['user'];
        echo '</td><td bgcolor="#eefaff" class="contentright">';
        echo $row['reason'];
        echo '</td></tr>';
    }
    echo '</table></div></div>';
}
?>
4

1 回答 1

0

更新

对不起,重新阅读问题。要检查同一页面上的多个表单,您需要为每个表单添加一个提交按钮并为其命名:

<?php
if (!empty($_POST) && isset($_POST['reasonsubmit'])) {
    echo 'Submitted reason form';
}
if (!empty($_POST) && isset($_POST['namesubmit'])) {
    echo 'Submitted name form';
}
?>

<form action="reason.php" method="post">
    <input type="text" name="reason" id="reason" />
    <input type="submit" name="reasonsubmit" />
</form>
<form action="name.php" method="post">
    <input type="text" name="name" id="name" />
    <input type="submit" name="namesubmit" />
</form>

或者,如果您不想为提交按钮命名,您可以在每个表单中添加一个隐藏字段,您将获得相同的行为。

<form action="reason.php" method="post">
    <input type="hidden" name="reasonsubmit" id="reasonsubmit" />
    <input type="text" name="reason" id="reason" />
    <input type="submit" />
</form>
<form action="name.php" method="post">
    <input type="hidden" name="namesubmit" id="namesubmit" />
    <input type="text" name="name" id="name" />
    <input type="submit" />
</form>
于 2013-08-28T14:46:20.380 回答