开发者

How to retrieve value from the Check boxes?

开发者 https://www.devze.com 2023-02-16 21:48 出处:网络
I\'m trying to get the emails corresponding to the checkbox using the following codes. But, I\'m not getting the correct checked emails in the new variable. Can anyone please check ??

I'm trying to get the emails corresponding to the checkbox using the following codes. But, I'm not getting the correct checked emails in the new variable. Can anyone please check ??

<?php
include("connection.php");
$username=$_SESSION['username'];
$query=mysql_query("SELECT * FROM contacts WHERE username=开发者_高级运维'$username'");
$num=mysql_num_rows($query);
$info=mysql_fetch_array($query);
$i=0;
$msg='';
?>
  <table width="672" border="0">
<?php 
$i=0;
while($info)
{
?>
<form action="compose.php" method="post">
<tr style="font-size:14px;">
    <td width="21" bgcolor="#f2f2f2"> <input type="checkbox" name="add" onSelect="<?php $msg=$msg.$info['email'].", ";?>"/> </td>
    <td width="229" bgcolor="#f2f2f2"> <?php  echo $info['email']; ?> </td>
    <td width="408" bgcolor="#f2f2f2"> <?php  echo $info['name']; ?> </td>
  </tr>
<?php 
$info=mysql_fetch_array($query);
$i++;
}

$_SESSION['contacts']=$msg;
?>
<tr><td></td><td></td><td><br />
<input class="new-button" type="submit" value="Insert & Compose" name="submit" /></td>
</tr>
</form>



</table>


To get any value back for checkboxes they must have a value=. In your case you probably would want the value to be the according email address.

One problem with your code is using onSelect= instead of value=, and second you didn't print the actual value into the page. Rewrite it to:

<td width="21" bgcolor="#f2f2f2">
    <input type="checkbox" name="add"
     value="<?php print $info['email']; ?>"/> </td>

If you need the $msg variable to do something, assemble it after the output.


<input type="checkbox" name="add" value="<?php echo $msg.$info['email'];?>"/>

checkbox does not have onSelect event probobly you got value in mind and in PHP code you should echo and what .", " is for?

0

精彩评论

暂无评论...
验证码 换一张
取 消