dongpai1942 2012-03-30 02:49
浏览 50
已采纳

php / mysql复选框与True对比1

this should not be hard but I'm struggling with it so I thought I'd request help as I could not finding anything specific on web.

I am posting from a checkbox on a form. When I look at the querystring in browser window when I freeze output, it shows, the names of the variables = on. Similarly, when I echo the posted values they show up as on. The problem is when inserting into the dbase although inputting TRUE works, on does not. Fieldtype is tinyint(1). Do I have to convert all the ons to TRUEs. I feel like this has never been a problem before.

<form action="processform.php" method="post">
<input type = "checkbox" name="var1" CHECKED>
<input type = "checkbox" name="var2" CHECKED>
<input type="submit" name="submit" value="submit"></form>

script on other end.

$var1 = $_POST['var1'];
$var2 = $_POST['var2'];
echo $var1; //echoes "on"

$sql = "INSERT into table (var1,var2) VALUES (TRUE,TRUE)"; //works
$sql = "INSERT into table (var1,var2) VALUES ($var1,$var2)"; //does not work.
$sql = "INSERT into table (var1,var2) VALUES ('$var1','$var2')"; //does not work.

mysql_query($sql);

Is this a typo? Can't imagine you really need to change "on" blank to TRUE or FALSE for each variable

  • 写回答

7条回答 默认 最新

  • dsxml2169 2012-03-30 02:57
    关注

    You need to include a value="" field if you want to return a value other then ON

    <input type = "checkbox" name="var2" value="1" CHECKED>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数