Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have check box array,if I check the check box the details of specific check box value should be displayed on another page. I tried with session variables but it will take value only once. If I go back and check the different check box , the older value is displayed..I also used unset($_session['value'])...Is there any other way to accomplish this task?
Posted

I have drafted a quick example, try it:
<html>
<body>

<?php
// This PHP script will only run on post back from submit
if(isset($_POST['submit'])){
    if(!empty($_POST['sports'])){
        // loop to retrieve checked values
        foreach($_POST['sports'] as $selected){
            echo $selected."</br>";
        }
    }
}
?>

<form action="#" method="post">
<input type="checkbox" name="sports[]" value="jogging">Jogging<br/>
<input type="checkbox" name="sports[]" value="swimming">Swimming<br/>
<input type="checkbox" name="sports[]" value="cycling">Cycling<br/>
<input type="submit" name="submit" value="Send"/>
</form>

</body>
</html>

Checkbox allows multiple value, suffix its name with [], e.g. name="sports[]"; on the server side, loop through this name to get the checked elements in the array.
 
Share this answer
 
v2
Comments
Member 14817308 29-Apr-20 12:17pm    
Thank you so much.... It helped me lot
There are two ways to transmit data from one page to another that are commonly used that don't rely on session variables.

AJAX and <form>

HTML
The form has another page as a target (or chains to one) and the values can be retrieved (each checkbox needs a name='') from the target page. I prefer $_REQUEST['the name']. Going back to the previous page (i.e., the one with the form) typically clears all data. If you submit it again it will use the current data with no memory of the previous data.

AJAX is executed from a local javaScript and you pass the variables when you execute the send procedure. Unlike the form, it doesn't cause your to load a new page but rather can update your current page. Although not exactly what you want to do, it can be adapted and may give you a better way of thinking about your solution

All of this can be studied via HERE [^]

 
Share this answer
 
v2
Comments
smrithi92 9-Mar-15 3:08am    
Thank you... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900