Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/266639-check-box-with-input-type-button/
Share on other sites

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.

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.

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.