jeudi 14 avril 2016

How to extract checkbox data into another page in PHP (checkbox data is populated from MySQL)

i have created a list of checkbox data which has been populated with values from mysql database. Now i would like to extract the selected checkbox data into another page "functions_two.php" when clicked submit. i can't seem to figure out a way to do this as the checkbox data has been taken from the database.

below is my code:

<?PHP

$hostname = "localhost";
$username = "root";
$password = "root";
$databaseName = "my computer";

$connect = mysqli_connect($hostname, $username, $password, $databaseName);


// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }



?>


<html>  
<body>


<form name="aform" action="functions_two.php" method="POST">


<div id="collegelane">College Lane campus:</div>


<?php


  $s = '';
  $j = 0;
  if ($q = $connect->query("SELECT * FROM `campus`")) {
    while ($line = $q->fetch_assoc()) {
      $s.= '<input type="checkbox" name="car'.$j.'" value="'.$line['room'].'">'.$line['room'];
    }
  }
  echo $s;
?>

</div>

</br>
</br>


<div id="dehav">De Havilland campus:</div>


<?php
  $a = '';
  $b = 0;
  if ($t = $connect->query("SELECT * FROM `campus_two`")) {
    while ($line = $t->fetch_assoc()) {
      $a.= '<input type="checkbox" name="car'.$b.'" value="'.$line['room'].'">'.$line['room'];
    }
  }
  echo $a;
?>

</br>
</br>


<div id="next"><input type="submit" name="next" Value="next"/></div>
</form>



</body>
</html>

Aucun commentaire:

Enregistrer un commentaire