帮助PHP和HTML复选框 [英] Help PHP and HTML Checkboxes

查看:129
本文介绍了帮助PHP和HTML复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用复选框和PHP的帮助。我只是试图确定是否选中复选框的值。

I need help working with Checkboxes and PHP. I'm just trying to determine a value on whether the checkbox is checked or not with PHP.

示例:

Example:

<?php
include ("inc/conf.php");
$id = $_SESSION['id'];

if(isset($_POST['subfrm'])){
  $gtid = $_REQUEST['tid'];

  $ch1 = $_REQUEST['ch1'];
  if($ch1 == "ON"){
    $gch1 = "Y";
  } else {
    $gch1 = "N";
  }

  $ch2 = $_REQUEST['ch2'];
  if($ch2 == "ON"){
    $gch2 = "Y";
  } else {
    $gch2 = "N";
  }

  mysql_query("UPDATE SET ctable ch1='$gch1', ch2='$gch2' WHERE id='$gtid'");
}
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="tid" value="<?php echo $id; ?>" />
<input type="checkbox" name="ch1" />Hats
<input type="checkbox" name="ch2" />Watches
<textarea name="thetext"></textarea>
<input type="submit" name="subfrm" value="PUNCH ME" />
</form>


推荐答案

if(isset($_REQUEST["ch1"])){
    $gch1 = "Y";
} else {
    $gch1 = "N";
}
if(isset($_REQUEST["ch2"])){
    $gch2 = "Y";
} else {
    $gch2 = "N";
}

您无需查看该值是什么,因为它如果未检查,则不会提交任何数据,如果是,它将提交的值。

You don't need to check to see what the value is, because it will not submit any data whatsoever if it isn't checked, and it will submit a value of on if it is.

这篇关于帮助PHP和HTML复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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