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