NaniG Posted August 3, 2012 Share Posted August 3, 2012 Hi to all, Here is the my form structure code <form name='form1' method='POST'> <table cellpadding="0" cellspacing="2" width="100%" border="0"> <tr> <td><input type="checkbox" name="EmpFeedback"></td> <td>Employee Number</td> <td>Employee Name</td> <td>Employee Designation</td> </tr> <?php $selEmp = mysql_query("select * from employee") or die(mysql_error()); $numEmp = mysql_num_rows($selEmp); if($numEmp>0) { while($rowEmp = mysql_fetch_array($selEmp)) { ?> <tr> <td><input type="checkbox" name="EmpFeedback[]" value="<?php echo $rowEmp['empno']; ?>" /></td> <td><?php echo $rowEmp['empno']; ?></td> <td><?php echo $rowEmp['empname']; ?></td> <td><?php echo $rowEmp['empdesignation']; ?></td> </tr> <?php } } ?> <tr><td colspan="4" align="center"><input type="button" name="btnFeedback" value="Send Feedback" onClick="javascript: document.location.href='Feedback.php';" /></td></tr> </table> </form> When i checked the check box and clicked on button, it will redirects to the targeted page (ie Feedback.php). my intention is to send an feedback report to that particular selected (checked) employee. But am not able to get that particular checked Employee Number. in my Feedback.php page $empNumber = $_POST['EmpFeedback']; Am little bit confused. Please help me out from these issue. Quote Link to comment https://forums.phpfreaks.com/topic/266639-check-box-with-input-type-button/ Share on other sites More sharing options...
scootstah Posted August 3, 2012 Share Posted August 3, 2012 I would change the checkbox to this: <input type="checkbox" name="EmpFeedback[<?php echo $rowEmp['empno']; ?>]" value="1" /> Now, the array indexes will be the employee ID. When you process it, you will have to loop through the selected checkboxes and then do whatever. Something like this: if (isset($_POST['EmpFeedback']) && !empty($_POST['EmpFeedback'])) { $selectedEmps = $_POST['EmpFeedback']; foreach(array_keys($selectedEmps) as $emp) { // ... } } In the foreach loop, $emp will be an employee ID. Quote Link to comment https://forums.phpfreaks.com/topic/266639-check-box-with-input-type-button/#findComment-1366558 Share on other sites More sharing options...
NaniG Posted August 5, 2012 Author Share Posted August 5, 2012 Thanks for the reply Scootstah...! When i tried it am not getting any result. Quote Link to comment https://forums.phpfreaks.com/topic/266639-check-box-with-input-type-button/#findComment-1366910 Share on other sites More sharing options...
scootstah Posted August 5, 2012 Share Posted August 5, 2012 Can you post your new code? Quote Link to comment https://forums.phpfreaks.com/topic/266639-check-box-with-input-type-button/#findComment-1366947 Share on other sites More sharing options...
NaniG Posted August 6, 2012 Author Share Posted August 6, 2012 Thanks for the reply Scootstah...! I have to changed the input type checkbox as <input type="checkbox" name="EmpFeedback[]" value="<?php echo $rowEmp['empno']; ?>" > and in my feedback.php page <?php if (isset($_POST['EmpFeedback']) && !empty($_POST['EmpFeedback'])) { $selectedEmps = $_POST['EmpFeedback']; foreach($selectedEmps as $key=>$emp) { echo $emp; } } ?> Now its working fine with me...! Thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/266639-check-box-with-input-type-button/#findComment-1367085 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.