0

Hello All,

I am new to PHP and the requirement is, i need to design a form with multiple checkboxes with same name. I tried using arrays and the code is

<td>
 <input type="checkbox" name="eroom_status[]" value="empty" 
  <?php if(isset($_POST['eroom_status'])) {
   if (in_array('empty',$POST['eroom_status']) {
        $check = 'checked';}
   }  echo $check;?>  >
   </td>

                                    <td>
                                        <input type="checkbox" name="eroom_status[]" value="Rejected"
                                        <?php  if(isset($_POST['eroom_status'])) {
                                            if (in_array('Rejected',$POST['eroom_status'])) { $check = 'checked'; }
                                               }?> <?php echo $check;?> >
                                    </td>
                                    <td>
                                        <input type="checkbox" name="eroom_status[]" value="New To Airbus"
                                        <?php if(isset($_POST['eroom_status'])) {
                                            if (in_array('New To Airbus',$POST['eroom_status'])) { $check = 'checked'; }
                                        }  echo $check;?> >
                                    </td>
                                    <td>
                                        <input type="checkbox" name="eroom_status[]" value="Closed"
                                        <?php  if(isset($_POST['eroom_status'])) {
                                            if (in_array('Closed',$POST['eroom_status'])) { $check = 'checked'; }
                                        } echo $check; ?> >
                                    </td>
                                    <td> <input type="checkbox" name="eroom_status[]" value="Closed with Comments"
                                        <?php  if(isset($_POST['eroom_status'])) {
                                            if (in_array('Closed with Comments',$POST['eroom_status'])) { $check = 'checked'; }
                                        } echo $check; ?> >
                                    </td>.

I am getting an error message. In in_array() function the second parameter is null. Please help me regarding this issue.

Edited by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by nileshgr
0

You're using $POST instead of $_POST. Use this corrected code-

<td>
 <input type="checkbox" name="eroom_status[]" value="empty" 
  <?php if(isset($_POST['eroom_status'])) {
   if (in_array('empty',$_POST['eroom_status']) {
        $check = 'checked';}
   }  echo $check;?>  >
   </td>

                                    <td>
                                        <input type="checkbox" name="eroom_status[]" value="Rejected"
                                        <?php  if(isset($_POST['eroom_status'])) {
                                            if (in_array('Rejected',$_POST['eroom_status'])) { $check = 'checked'; }
                                               }?> <?php echo $check;?> >
                                    </td>
                                    <td>
                                        <input type="checkbox" name="eroom_status[]" value="New To Airbus"
                                        <?php if(isset($_POST['eroom_status'])) {
                                            if (in_array('New To Airbus',$_POST['eroom_status'])) { $check = 'checked'; }
                                        }  echo $check;?> >
                                    </td>
                                    <td>
                                        <input type="checkbox" name="eroom_status[]" value="Closed"
                                        <?php  if(isset($_POST['eroom_status'])) {
                                            if (in_array('Closed',$_POST['eroom_status'])) { $check = 'checked'; }
                                        } echo $check; ?> >
                                    </td>
                                    <td> <input type="checkbox" name="eroom_status[]" value="Closed with Comments"
                                        <?php  if(isset($_POST['eroom_status'])) {
                                            if (in_array('Closed with Comments',$_POST['eroom_status'])) { $check = 'checked'; }
                                        } echo $check; ?> >
                                    </td>.
0

Hello itech7,

Thats a good finding..that too in a badly formated code... Thanku very much:)

You're using $POST instead of $_POST. Use this corrected code-

<td>
 <input type="checkbox" name="eroom_status[]" value="empty" 
  <?php if(isset($_POST['eroom_status'])) {
   if (in_array('empty',$_POST['eroom_status']) {
        $check = 'checked';}
   }  echo $check;?>  >
   </td>

                                    <td>
                                        <input type="checkbox" name="eroom_status[]" value="Rejected"
                                        <?php  if(isset($_POST['eroom_status'])) {
                                            if (in_array('Rejected',$_POST['eroom_status'])) { $check = 'checked'; }
                                               }?> <?php echo $check;?> >
                                    </td>
                                    <td>
                                        <input type="checkbox" name="eroom_status[]" value="New To Airbus"
                                        <?php if(isset($_POST['eroom_status'])) {
                                            if (in_array('New To Airbus',$_POST['eroom_status'])) { $check = 'checked'; }
                                        }  echo $check;?> >
                                    </td>
                                    <td>
                                        <input type="checkbox" name="eroom_status[]" value="Closed"
                                        <?php  if(isset($_POST['eroom_status'])) {
                                            if (in_array('Closed',$_POST['eroom_status'])) { $check = 'checked'; }
                                        } echo $check; ?> >
                                    </td>
                                    <td> <input type="checkbox" name="eroom_status[]" value="Closed with Comments"
                                        <?php  if(isset($_POST['eroom_status'])) {
                                            if (in_array('Closed with Comments',$_POST['eroom_status'])) { $check = 'checked'; }
                                        } echo $check; ?> >
                                    </td>.
0

I manually didn't replace each error. Since I use Linux, I have all sorts of text processing utitilies available on the command line. I replaced all of them with just one line. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.