【发布时间】:2011-09-25 13:45:50
【问题描述】:
我在使用 Checkboxes 和 PHP 时需要帮助。我只是想确定是否使用 PHP 选中复选框的值。
例子:
<?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>
【问题讨论】:
-
请在查询数据库之前清理用户输入。使用您当前的代码,您很容易受到 SQL 注入的攻击