2015-02-12 34 views
0

我正在为具有不同列的复选框值创建数据库。如何插入数据库?因为我已经将复选框值存储在不同的列名中,我的列名是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
if(isset($_POST['allsubject']){$allsubject=1;} (OR VALUE YOU WANT) 
+0

,如果我做这样的(isset($ _ POST [ 'allsubject'])) { \t $ allsubject = $ _ POST [ 'allsubject'] ; } else { \t $ allsubject ='null'; } 如果我从sql中获取?谁正在使用allsubject空值即将到来如何避免该形式db。 – user2715480 2015-02-12 09:21:37

+0

对不起,我不明白你想在数据库中避免什么? – 2015-02-12 09:25:16

+0

SELECT * FROM'studentinfo'这里我发送的空字符串不包含值.so如果我想列出它包含空字符串的表值,以避免那个? – user2715480 2015-02-12 09:32:33

相关问题