如何从复选框检索值? [英] How to retrieve value from the Check boxes?

查看:130
本文介绍了如何从复选框检索值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用以下代码获取与该复选框相对应的电子邮件。但是,我没有得到正确的检查电子邮件在新的变量。

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>


推荐答案

value =

您的代码的一个问题是使用 onSelect = 而不是 value = ,其次你没有打印实际值到页面。重写为:

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>

如果您需要 $ msg 做某事,在输出之后组装它。

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

这篇关于如何从复选框检索值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆