I'm sure this is a pretty simple question, but it's got me baffled.
$id = $_POST['id'];
$sem = $_POST['sem'];
$year = $_POST['year'];
if(is_array($_POST['mark']) and
is_array($_POST['gred']) and
is_array($_POST['code']) and
is_array($_POST['subject']))
{
$values = array();
foreach($_POST['mark'] as $key => $mark)
{
$gred = $_POST['gred'][$key];
$code = $_POST['code'][$key];
$subject = $_POST['subject'][$key];
$values[] = "('$id','$sem','$year','$mark','$gred','$code','$subject')";
}
$query = "INSERT INTO result ".
"(id_stud, sem, year, mark, gred, subject_code, name_subject) ".
"VALUES " . implode(",", $values);
$result = mysql_query($query) or die("Query failed: $query - " . mysql_error());
}
This foreach loop insert all the data even user do not input the mark and gred input..In the database value of gred and mark as NULL.
i want to insert all the data only when user input the mark and gred only..
Please help me..