warrenk Posted February 8, 2007 Share Posted February 8, 2007 I am trying to view the value of a checkbox. When I use the code below, I get the value with extra information if($_SERVER['REQUEST_METHOD']=='POST') { $a=$_POST['checkbox']; print_r($a); } The value I am getting from the above code - 'Array ( [0] => mm_r.gif)' ....I just want the actual value - 'mm_r.gif' Link to comment https://forums.phpfreaks.com/topic/37659-echo-value-of-a-checkbox/ Share on other sites More sharing options...
The Little Guy Posted February 8, 2007 Share Posted February 8, 2007 instead of print_r($a), use echo $a Link to comment https://forums.phpfreaks.com/topic/37659-echo-value-of-a-checkbox/#findComment-180138 Share on other sites More sharing options...
warrenk Posted February 8, 2007 Author Share Posted February 8, 2007 if($_SERVER['REQUEST_METHOD']=='POST') { $a=$_POST['checkbox']; echo $a; echo "<br>"; print_r($a); } Here are the results: Array <==========results of echo $a Array ( [0] => 27292181.jpg ) <=========results of print_r($a) The value I am looking for is the file name (ie. 27292181.jpg). Thanks for any help, Warren Link to comment https://forums.phpfreaks.com/topic/37659-echo-value-of-a-checkbox/#findComment-180147 Share on other sites More sharing options...
The Little Guy Posted February 8, 2007 Share Posted February 8, 2007 if($_SERVER['REQUEST_METHOD']=='POST') { echo $_POST['checkbox']; } Link to comment https://forums.phpfreaks.com/topic/37659-echo-value-of-a-checkbox/#findComment-180158 Share on other sites More sharing options...
The Little Guy Posted February 8, 2007 Share Posted February 8, 2007 the above will only work for one check box, other wise you need to place the checkboxes in an array. So... If your checkboxes look like so... Square brace must be on the end, it defines an array <input type="checkbox" value="123.jpg" name="view[]"> <input type="checkbox" value="456.jpg" name="view[]"> <input type="checkbox" value="789.jpg" name="view[]"> then your php will look like this: <?php if($_SERVER['REQUEST_METHOD']=='POST') { foreach($_POST['view'] as $value){ echo $value.'<br>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/37659-echo-value-of-a-checkbox/#findComment-180163 Share on other sites More sharing options...
warrenk Posted February 8, 2007 Author Share Posted February 8, 2007 Thanks for your help! This is exactly what I was after. Warren Link to comment https://forums.phpfreaks.com/topic/37659-echo-value-of-a-checkbox/#findComment-180207 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.