vendredi 2 novembre 2018

Selected Checkbox value(s) to a different page

Iam new to this stuff. But I want to send checked checkbox value(s) to different page. Iam illustrating what i desire with code below;

php_checkbox.php file

<!DOCTYPE html>
<html>
<head>
<title>Get Values of Multiple Checked Checkboxes</title>
<link rel="stylesheet" href="css/php_checkbox.css" />
</head>
<body>
<div class="container">
<div class="main">
<center>
<h2>PHP: Get Values of Multiple Checked Checkboxes</h2>
<form action="checkbox_value.php" method="post">
<label class="heading">Select Your Technical Exposure:</label><p>
<input type="checkbox" name="check_list[]" 
value="C/C++"><label>C/C++       </label> <p>
<input type="checkbox" name="check_list[]" value="Java">    
<label>Java</label> <p>
<input type="checkbox" name="check_list[]" value="PHP"><label>PHP</label><p>
<input type="checkbox" name="check_list[]" 
value="HTML/CSS"><label>HTML/CSS</label><p>
<input type="checkbox" name="check_list[]" 
value="UNIX/LINUX"><label>UNIX/LINUX</label><p>
<input type="submit" name="submit" Value="Submit"/>
<p>
</form>
</div>
</div>
</body>
</html>

checkbox_value.php file

<?php
if(isset($_POST['submit'])){
if(!empty($_POST['check_list'])) {
// Counting number of checked checkboxes.
$checked_count = count($_POST['check_list']);

foreach($_POST['check_list'] as $selected) {
echo "<p>".$selected ."</p>";}

for ($x = 1; $x <= $checked_count; $x++) {

?>


<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;    
}
</style>
</head>
<body>

<h2>Cell that spans two columns</h2>
<p>To make a cell span more than one column, use the colspan attribute.</p>

<table style="width:50%">
<tr>
<td>Technology</td>
<td><?php echo $selected; ?></td>
</tr>
</table>

<?php
} 
}
else{
}
}
?>

</body>
</html>

The above code work. The problem is when I select Java and PHP, I get PHP displayed in both tables. When I select 3 options, the last option get displayed in all tables. What I need is when I select e.g. PHP, JAVA, and UNIX/LINUX, the 3 options (PHP, JAVA, UNIX/LINUX) be displayed on the tables separately - PHP on the first table, Java on the second table and UNIX/LINUX on the third table. When I select only 2 (e.g. Java and PHP), I want Java on the first table and PHP on the second. Please help.




Aucun commentaire:

Enregistrer un commentaire