$b_lname = $_POST['bstudnt_lname'];
$b_fname = $_POST['bstudnt_fname'];
$b_mname = $_POST['bstudnt_mname'];
$department = $_POST['class_department'];
$section = $_POST['section_name'];
$year_grade = $_POST['faclty_advse_year'];
$school_id ="a3arew542q3dq";
$counter2 = 0;
$button = $_POST['add_students'];
if(isset($button)){
foreach($b_lname as $blast => $x){
$arraylname[] ="".$x;
}
foreach($b_fname as $bfirst => $y){
$arrayfname[] ="".$y;
$counter2+=1;
}
foreach($b_mname as $bmid => $z){
$arraymname[] ="".$z;
$counter2+=1;
}
for($v=0;$v<=$counter2-1;$v++){
if($arrayfname[$v]!="" && $arraymname[$v]="" && $arraylname[$v]=""){
$insert = "INSERT INTO students(school_id,firstname,middlename,lastname,gender,department,section,year_grade)
VALUES('$school_id','$arrayfname[$v]','$arraymname[$v]','$arraylname[$v]','male','$department','$section','$year_grade')";
if(@!mysql_query($insert)){
die('error insert'.mysql_error());
}
}
}
}
但是我遇到麻烦,如果数组没有值,它就不会插入数据库中。 我做了一个if语句,但我猜它没用。
答案 0 :(得分:0)
if (count($array)) {
//insert into db
} else {
// array is emtpy
}
答案 1 :(得分:0)
问题在于:
if($arrayfname[$v]!="" && $arraymname[$v]="" && $arraylname[$v]=""){
您使用单个=
作为后两个条件。将其更改为==
或===
。