我正在为具有不同列的复选框值创建数据库。如何插入db?因为我已经将复选框值存储在不同的列名中,我的列名是allsubject,science,maths。
my questions are:
1.if user checks allsubject,the value is inserted, the other two column is going with null values.
2.is this way of storing value is correct because among three check box user select any values, I want to clarify this?
3.More over I want to store the values in this manner only
dbstructure:
**allsubject science maths**
allsubject science maths
allsubject science
maths
allsubject
Myform:
<form name="f1" action="" method="post">
Student Name:<input type="text" name="sname" value=""/>
All Subject:<input type="checkbox" name="allsubject" value="allsubject"/>
Science<input type="checkbox" name="science" value="science"/>
Maths<input type="checkbox" name="maths" value="maths"/>
<input type="submit" name="submit" value="submit"/>
</form>
**myphp value is:**
<?php
mysql_connect('localhost','root','');
mysql_select_db('checkbox');
if(isset($_POST['submit'])=='submit')
{
$allsubject=$_POST['allsubject'];
$science=$_POST['science'];
$maths=$_POST['maths'];
$sql=mysql_query("insert into studentinfo (allsubject,science,maths) values ('".$allsubject."','".$science."','".$maths."')");
}
?>
答案 0 :(得分:0)
if(isset($_POST['allsubject']){$allsubject=1;} (OR VALUE YOU WANT)