Jump to content

Echo Value Of A Checkbox


warrenk

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.