php - Multiple forms on same page - If empty -
i'm in process of coding mysql search page , i'm unable work out how make if there's no data put in 1 form it'll nothing, , if there's data in other form it'll search database value.
<?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 * `log1` `user` '%$name%'") or die(mysql_error()); $kicklogreason = mysql_query("select * `log1` `user` '%$reason%'") or die(mysql_error()); if($name == ""){ echo "you must enter name 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>'; } ?>
update
sorry, re-read question. check multiple forms on same page need add submit button each form , give name:
<?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>
alternatively, if didn't want give submit button name can add hidden field each form , same behavior.
<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>
Comments
Post a Comment