如何使用php将复选框值保存到mysql数据库中 [英] how to save checkbox value into mysql database using php
问题描述
您好我有一个表格,其中有一个复选框,我想将复选框的值保存到我的数据库中,但当我点击复选框并保存时,它工作正常,当我尝试保存表单时未检查chekbox它显示未定义的索引可以任何一个帮助我
这里是我的html
< input type =checkboxname =activevalue =1>< / input>
这里是我的php
$ nactive = $ _POST [active];
这里是我保存的部分
<$ p $
$ b $ mysql_query(INSERT INTO`usermain`(`username`,`password`,level,active,`zimname`,zimmob,`email`,admin,makhtab)
值
('$ nuser','$ npwd','$ nlevel','$ nactive','$ nzname','$ nzmob','$ nemail','0','$ makh'))或死亡(mysql_error());
如果复选框没有被选中,实际上并没有在您的POST请求中发送数据。您需要检查是否设置了该值,然后相应地更新您的变量。
$ inactive = isset($ _ POST [active ])? $ _POST [active]:0;
hi i have a form which has a checkbox and i want to save the value of the checkbox into my database but when i click on the checkbox and save it it works fine and when i try to save the form without checking on the chekbox it shows undefined index can any one help me out
here is my html
<input type="checkbox" name="active" value="1"></input>
here is my php
$nactive = $_POST["active"];
here is my save part
mysql_query("INSERT INTO `usermain`( `username`, `password`, level, active,`zimname`, zimmob, `email`, admin, makhtab)
Values
('$nuser', '$npwd', '$nlevel', '$nactive', '$nzname', '$nzmob', '$nemail', '0', '$makh')") or die(mysql_error());
If the checkbox isn't checked, the browser won't actually send the data in your POST request. You'll need to check if the value is set, and then update your variable accordingly.
$inactive = isset($_POST["active"]) ? $_POST["active"] : 0;
这篇关于如何使用php将复选框值保存到mysql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!