Jump to content

checkboxes


anser316

Recommended Posts

Hi im having a problem with checkboxes and using them to choose rows to send and on another form retreive. Im not sure how the counter should be done with the checkbox. Is the checbox creation right?

I.E. name=ticked[$row]

 

mysql_connect("localhost", "root", "") or die(mysql_error());
echo "<i>Connected to Sales Database</i><br>";
mysql_select_db("db1") or die(mysql_error());


$result =mysql_query("SELECT d.drug_id,d.drug_name, b.branch_details
FROM drugs d, branch_items i, branch b
WHERE d.drug_id=i.drug_id
AND b.branch_id=i.branch_id");


echo "<br><br>";
echo "<B>Ordered Items</B><p>";
echo "<form action= constore.php method=POST>";
echo "<table border='1'>";
echo "<tr> <th>DRUG ID</th> <th>DRUG NAME</th> <th>BRANCH</th></tr>";
while($row = mysql_fetch_array( $result )) {

echo "<tr><td>"; 
echo $row['drug_id'];
echo "</td><td>";
echo $row['drug_name'];
echo "</td><td>";
echo $row['branch_details'];
echo "</td><td>";
echo "<input type=checkbox name=ticked[$row] value='yes'>";
echo "</td></tr>"; 
}
echo "</table>";
echo "<input type =submit value= Submit>";
echo "<input type = reset>";
echo "</form>";

 

Link to comment
https://forums.phpfreaks.com/topic/98683-checkboxes/
Share on other sites

I would store the drug_id in the checkbox array.

 

So change your checkbox creation line to:

echo "<input type='checkbox' name='ticked[]' value='{$row['drug_id']}'>";

 

 

Then at the top of your page, you can do this to see what has been checked:

<?php

if (isset($_POST['ticked'])){
   
   echo "The following drugs were chosen:<p>";

   foreach ($_POST['ticked'] as $drugID){
      echo $drugID.'<br>';
   }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/98683-checkboxes/#findComment-505049
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.