PHP Search with Checkbox
PHP Search with Checkbox
1st step: Make Database “checkboxes”.
2nd step: Add Table “tblx”
3rd step: Add Columns “id, city, country”
Database of PHP Search with Checkbox
PHP Code of PHP Search with Checkbox
Make two files, “index.php” and “select.php”.
Index.php code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <?php $conn = mysqli_connect('localhost','root','','checkboxes'); $sql= mysqli_query($conn,'SELECT * FROM tblx'); ?> <form Method="post" Action="select.php" > <?php while($result=mysqli_fetch_assoc($sql)) { ?> <tr> <td width="30%" align="center"> <br> <input name="<?php echo $result['id']?>" type="checkbox" id="<?php echo $result['id']?>" value="<?php echo $result['id']?>"> </label></td> <td width="30%" align="center"><?php echo $result['city']?></td> <td width="30%" align="center"><?php echo $result['country']?></td> </tr > <?php } ?> <tr> <br> <td align="center"><input type="submit" name="submit" value="FindID" /></td> </tr> </table> </form> |
select.php Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?php $conn = mysqli_connect('localhost','root','','checkboxes'); $sql = mysqli_query($conn,'SELECT * FROM tblx'); $x = NULL; while($fetch = mysqli_fetch_assoc($sql)) { $x++; if(isset($_POST[$x])) { echo " ".$_POST[$x]." "; $sql1 = mysqli_query($conn,"SELECT `city` FROM `tblx` WHERE id=$x"); while($result = mysqli_fetch_array($sql1)) { echo $result['city']."<br>"; } } } ?> |
Output
index.php output:
Download Code – Search with Checkbox PHP