我已經表命名爲subject
。我不得不列id
(PK),subject_name
,total_class
,attendence
和cnic
(FK)。我的用戶填寫表格並提交。我通過表單的post方法獲得了值。在形式上,我有6個科目,併爲每個科目我有total_class
,attendence
,subject_name
。 這裏是我的代碼我怎麼可以插入6倍值到MySQL表在單個查詢
if($_SERVER['REQUEST_METHOD']=='POST')
{
$form=$_POST[form'];
$s1=$_POST['sub1'];
$s1=$_POST['sub2'];
$s1=$_POST['sub3'];
$s1=$_POST['sub4'];
$s1=$_POST['sub5'];
$s1=$_POST['sub6'];
$month=$_POST['month'];
$total_attend_1=$_POST['Ts1'];
$total_attend_2=$_POST['Ts2'];
$total_attend_3=$_POST['Ts3'];
$total_attend_4=$_POST['Ts4'];
$total_attend_5=$_POST['Ts5'];
$total_attend_6=$_POST['Ts6'];
$attend_1=$_POST['Attend_s1'];
$attend_2=$_POST['Attend_s2'];
$attend_3=$_POST['Attend_s3'];
$attend_4=$_POST['Attend_s4'];
$attend_5=$_POST['Attend_s5'];
$attend_6=$_POST['Attend_s6'];
$query=mysql_query("INSERT INTO subject VALUE('','$s1','total_attend_1','$attend_1','$form','$month')") or die(mysql_error());
/*My query should be here.Should I write 6 insert queries?*/
我曾用
foreach($array as $attendee){
}
嘗試過,但沒有得到我的任務是什麼? 有人可以幫我嗎?
首先,那麼您需要了解[sql注入漏洞](http://bobby-tables.com),那麼您需要了解[數據庫規範化](http://en.wikipedia.org/wiki/Database_normalization) –
如果你有一個變量名在裏面有一個數字*,你應該使用一個數組* –
@sam:沒有錯誤的數字在他們的變量。但其中肯定有順序/重複數字的變量。 –