anser316 Posted March 30, 2008 Share Posted March 30, 2008 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 More sharing options...
pocobueno1388 Posted March 30, 2008 Share Posted March 30, 2008 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 More sharing options...
anser316 Posted March 30, 2008 Author Share Posted March 30, 2008 perfect! thanks a lot mate Link to comment https://forums.phpfreaks.com/topic/98683-checkboxes/#findComment-505067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.