jeudi 29 décembre 2016

How to check if check box has been checked in php

I have check boxes which display information from a database and was wonder how I would check if one of the radio buttons has been checked once the user clicks submit.

Here is my code.

  <?php 

                $query1 = "SELECT town FROM place WHERE ID = 1";

    
      $result1 = mysqli_query($con, $query1) or die("Invalid Query");

      while($row1 = mysqli_fetch_assoc($result1)){ 
        
        $town = $row1["town"];


echo "<input type=\"checkbox\" name=\"town\" value=\"$town\" />$town </br>";
        
        }

        $query2 = "SELECT town FROM place WHERE ID = 2";

    
      $result2 = mysqli_query($con, $query2) or die("Invalid Query");

      while($row2 = mysqli_fetch_assoc($result2)){ 
        
        $town = $row2["town"];


echo "<input type=\"checkbox\" name=\"town\" value=\"$town\" />$town </br>";
        
        
        }

                $query3 = "SELECT town FROM place WHERE ID = 3";

    
      $result3 = mysqli_query($con, $query3) or die("Invalid Query");

      while($row3 = mysqli_fetch_assoc($result3)){ 
        
        $town = $row3["town"];


echo "<input type=\"checkbox\" name=\"town\" value=\"$town\" />$town </br>";

        }



Aucun commentaire:

Enregistrer un commentaire