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' Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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']; } Quote Link to comment 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>'; } } ?> Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.