2015-02-12 33 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

相關問題