displaying data on to another page by check box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ma5ect
Forum Commoner
Posts: 35
Joined: Wed Jun 25, 2008 8:38 am

displaying data on to another page by check box

Post by ma5ect »

hi all.

I have a table on my webpage, i want the user to select a check box which is assigned to a field on the table and once the user submits the form, i want that check box data to be displayed on another page...


i have got the form with the check box and data field assigned but dont know how i can get it to display onto the next page..

form page code:

Code: Select all

<form name=orderform action="confirm-order.php">
  <table width="648" border="3" align="center">
    <tr>
      <td width="209"><div align="center" class="style12">
          <div align="center">Module name</div>
      </div></td>
      <td width="120"><div align="center" class="style12">
          <div align="center">Module ID</div>
      </div></td>
      <td width="158"><div align="center" class="style12">
          <div align="center">Credits</div>
      </div></td>
      <td width="117"><div align="center" class="style12">
          <div align="center">Completed</div>
      </div></td>
      <td width="61"><div align="center"></div></td>
    </tr>
    <?php do { ?>
    <tr>
      <td height="22"><span class="style9"><?php echo $row_Recordset2['Module name']; ?></span></td>
      <td><div align="center"><?php echo $row_Recordset2['Module ID']; ?></div></td>
      <td><div align="center"><?php echo $row_Recordset2['credits']; ?></div></td>
      <td><div align="center"><?php echo $row_Recordset2['Completed']; ?></div></td>
      <td><input name="module" type="checkbox" id="module" value="<?php echo $row_Recordset2['Module name']; ?>" /></td>
    </tr>
    <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>
  </table>
  <p align="center">
    <input type=submit value="Order" />
</form>
sparrrow
Forum Commoner
Posts: 81
Joined: Mon Oct 20, 2008 12:22 pm

Re: displaying data on to another page by check box

Post by sparrrow »

I'm not entirely sure what you're asking, but I'll take a stab at it. A checkbox has both a STATE and a VALUE. The value is passed if the checkbox is checked, and empty if unchecked. The state is going to be represented by "checked" or ""...or also checked="true" or "false". After the value is POSTed, you need to catch this to display the state. Try this:

Code: Select all

 <?php
if ($_POST['module']) {
   $modulestate = "checked";
}
?>
 
<input name="module" type="checkbox" id="module" value="<?php echo $row_Recordset2['Module name']; ?>" <?php echo $modulestate; ?>>
If the value for "module" is not null, then your HTML end up looking like:

Code: Select all

 <input name="module" type="checkbox" id="module" value="foo" checked> 
Post Reply