vendredi 15 avril 2016

php - how to make the script run different codes according to the selection from a checkbox

i am very new in php therefore i haven't been able to figure this out so i need your help.

In my first page, i have a 2 checkboxes which are values that were populated from the mysql database. those two values were taken from a database table called "campus", below is the code for the first page:

<html>  
<body>


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


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


<?php

// to connect to database 
require("user_connection.php");

$q = mysqli_query($connect, "SELECT * FROM `campus`");
    while ($line = mysqli_fetch_assoc($q)) {
     echo '<input type="checkbox" name="car" 
            value="'.$line['room'].'">'.$line['room'].'</br>';
   }


?>


</br>
</br>


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


</body>
</html>

this is the output of the code above http://ift.tt/1XAecMe

Now as you can see it has two checkbox values "C450" and "E300". when i select either one of these two values it takes me to the second page, where the value is echoed out. however what i want it to echo out is another piece of code according to the selection i make.

Say if i select "C450" i want it to run this code below, which creates another checkbox using values from the database table called C450, which i have already created:

<form action="final_page.php" method="POST">

<?php

// to connect to database 
require("user_connection.php");


// checkbox populated with values from database
$r = mysqli_query($connect, "SELECT * FROM `C450`");
    while ($line = mysqli_fetch_assoc($r)) {
     echo '<input type="checkbox" name="bike" 
            value="'.$line['computer_no'].'"><label>'.$line['computer_no'].'</label></br>';
   }

?>

</br>

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


</body>
</html>

however if i select "E300" i want it to run this code below, which also creates checkboxes whose values come from database table called E300.

<form action="final_page.php" method="POST">

<?php

// to connect to database 
require("user_connection.php");


// checkbox populated with values from database
$s = mysqli_query($connect, "SELECT * FROM `E300`");
    while ($line = mysqli_fetch_assoc($s)) {
     echo '<input type="checkbox" name="bike" 
            value="'.$line['computer_no'].'"><label>'.$line['computer_no'].'</label></br>';
   }

?>

</br>

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


</body>
</html>




Aucun commentaire:

Enregistrer un commentaire