Hi
I´m trying to insert a PHP array (school grades for one student) into Mysql. The array looks fine when I print it, and the sql consists of one insert per array row. However, only the last row of the array is inserted. What have I missed, and can anyone help?
regards,
ejret.
SQL TABLE:
CREATE TABLE students
.grades
(
id
int(10) unsigned NOT NULL auto_increment,
subjid
varchar(45) NOT NULL,
grade
varchar(45) default NULL,
studid
varchar(45) NOT NULL,
pid
varchar(11) NOT NULL,
date
timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (id
)
) ENGINE=InnoDB AUTO_INCREMENT=340 DEFAULT CHARSET=latin1
Main part of the form (a while loop):
echo "
";
Foreach loop and insert statement:
foreach ($_POST[‘grade’] as $int => $grade) {
$subjid = $_POST['subjid'][$int];
$pid=$_POST['pid'];
$studid= $_POST[‘studid’];
$sql = "INSERT INTO grades SET subjid='$subjid', studid='$studid',
grade=’$grade’, pid=’$pid’, date=NOW()";