Loading ...
Sorry, an error occurred while loading the content.

PHP CHECKBOXES

Expand Messages
  • Vasu
    hi, i am new to php, please help me regarding the check box problem. I have 3 file 1. test_equipment.php 2. view_test_equipment.php 3.
    Message 1 of 1 , Dec 15, 2010
    • 0 Attachment
      hi,
      i am new to php, please help me regarding the check box problem.


      I have 3 file
      1. test_equipment.php
      2. view_test_equipment.php
      3. Selected_test_equipment.php

      In test equipment i have one drop down box, which collected the product group from the database.
      when i click the submit button, all the related content are loaded in the page and a check box is also loaded.
      on selecting the check box and clicking the submit button.
      I want to view the records whcih are checked.in the form selected_test_equipment.php
      the code is given below


      1. test_equipment.php
      <! To connect to the Database >
      <?php
      include('db_connect.php');
      ?>
      <Html>
      <title><head>Test Equipment</head>
      </title>
      <Body bgcolor="#DDF3FF">
      <table border = 0 cellpading = 0 cellspacing = 0 width = 95% align=center>
      <tr>
      <td background="images/site images/heading_back.gif" align=center height=27><b>Test Equipment</td>
      </tr>
      </table>

      <form name="test_equipment" method="POST" action="view_test_equipment.php" enctype="multipart/form-data">
      <table border = 0 cellpading = 0 cellspacing = 0 width = 95%>
      <tr>
      <td height=27><b>Select a Group to view the details</td>
      </tr>
      </table>
      <table border=0>
      <td align='left' width = 150>
      Product Group
      </td>
      <td align='left'>
      <select name ="product_group" id = "product_group">
      <?php
      $result = mysql_query("select product_group from product_group_test_equipment order by product_group");
      echo '<option value = ""> Select a Product Group </option>';
      while ($row=mysql_fetch_array($result))
      echo '<option value = "'.$row[product_group].'">'.$row[product_group].'</option>';
      ?>
      </select>
      <input type = "submit" value="Submit" name="Submit">
      </td>
      </table>
      </form>
      </body>
      </html>

      2. view_test_equipment.php

      <?php
      include('db_connect.php');
      ?>
      <body>
      <form action="selected_test_equipment.php" method="POST">
      <table width="100%" border="0" cellpadding="0" cellspacing="0" align = "center">
      <tr>
      <td height="263" valign="top" border="0" cellspacing="0" cellpadding="0">
      <?php
      $pg = $_REQUEST['product_group'];
      $result_orders = mysql_query("Select * from test_equipment where product_group = '$pg'")or
      die ("<font color = red> Query Error </font>".mysql_error);
      $count=mysql_num_rows($result_orders);
      ?>
      <br>
      <center><font size="+1">Equipments availabe for testing -- Group : <?php echo $pg; ?></font></center>
      <br>
      <table width=80% border="1" cellspacing="1" cellpadding="1" class="Border" align = center>
      <tr align="left" bgcolor = "#05B0FF">
      <td align = center>
      <font size="3"><b>Equipment Name</b></font>
      <td align = center>
      <font size="3"><b>image</b></font>
      <td width="" align = center>
      <font size="3"><b>Description</b></font>
      <td width="" align = center>
      <font size="3"><b>Select for Enquiry</b></font>
      <?php
      while ($row=mysql_fetch_array($result_orders))
      {
      $image = "../admin/images/Test_Equipment_images/".$row['image_url'];
      $img = $image;
      echo'<tr>';
      echo'<td>'; echo $row["Equipment_name"]; echo'</td>';
      echo'<td width = 60>'; echo "<img src = '$img' width = 60 height = 60>"; echo'</td>';
      echo'<td>'; echo $row["Description"]; echo'</td>';
      echo'<td>';
      echo'<input type=checkbox name="id[]" value = $row["id"];>';
      // echo'<input type="checkbox" name = "id[]" value="Hello">';
      echo'</td>';
      echo'</tr>';
      }

      echo'</table>';
      echo'<br>';
      mysql_free_result($result_orders);
      echo'<input type="submit" name="formSubmit" value="Submit">';
      ?>

      3. Selected_test_equipment.php
      <?php
      include('db_connect.php');
      ?>
      <?php
      //$selected = implode(", ", $_SESSION['id']);
      $selected = $_POST['id'];
      //echo '<h1>'; echo $selected; echo '</h1>';
      $result = mysql_query("Select * from test_equipment where id = '$selected'")or
      die ("<font color = red> Query Error </font>".mysql_error);
      echo'<h1> You have selected </h1>';
      echo '<table border=1 cellspacing=2 cellpading=2>';
      echo '<tr>';
      echo '<td width=100>Sr No </td>';
      echo '<td width=200>Name</td>';
      echo '</tr>';
      echo '</table>';
      echo '<table border=1>';
      while ($row = mysql_fetch_array($result)) {

      $id=$row['id'];

      $Equipment_name=$row["Equipment_name"];
      $Description=$row["Description"];

      foreach($_POST["id"] as $id=>$value)
      //foreach($_POST["id"] as $value)

      {
      echo '<tr>';
      echo '<td width=100>'; echo $id; echo '</td>';
      echo '<td width=200>'; echo $Equipment_name; echo '</td>';
      // echo '<td align=center>' ; echo $row[$value]; echo'</td>';
      }
      }
      echo '</tr>';
      echo '</table>';
      ?>

      I am not able to getting the right result please help or suggest any othe method
      Thank
    Your message has been successfully submitted and would be delivered to recipients shortly.