Array
(
[subject] => Mathematics
[admissionno] => Array
(
[0] => MS3389
[1] => MS3387
[2] => MS3384
)
[name] => Array
(
[0] => Abdulbasit Alaka-Yusuf
[1] => Abdulbasit Alaka-Yusuf
[2] => Abdulbasit Alaka-Yusuf
)
[ca] => Array
(
[0] => 11
[1] => 14
[2] => 17
)
[assignment] => Array
(
[0] => 12
[1] => 15
[2] => 18
)
[exam] => Array
(
[0] => 13
[1] => 16
[2] => 19
)
[comment] => Array
(
[0] => qwerty
[1] => asdfghj
[2] => fghjcfb
)
[save] =>
)
I'm trying to insert this array into the database this is the code:
if(isset($_POST['save'])){
$id = isset($_POST['id']) && $_POST['id'] != '' ? $_POST['id'] : "";
$subject = isset($_POST['subject']) && $_POST['subject'] != "" ? $_POST['subject'] : "";
$admissionno = isset($_POST['admissionno']) && $_POST['admissionno'] != "" ? $_POST['admissionno'] : "";
$name = isset($_POST['name']) && $_POST['name'] != "" ? $_POST['name'] : "";
$ca = isset($_POST['ca']) && $_POST['ca'] != "" ? $_POST['ca'] : "";
$assignment = isset($_POST['assignment']) && $_POST['assignment'] != "" ? $_POST['assignment'] : "";
$exam = isset($_POST['exam']) && $_POST['exam'] != "" ? $_POST['exam'] : "";
$comment = isset($_POST['comment']) && $_POST['comment'] != "" ? $_POST['comment'] : "";
echo '<pre>';
print_r ($_POST);//die();
$admissionno = implode("','",$_POST['admissionno']);
$name = implode("','",$_POST['name']);
$ca = implode("','",$_POST['ca']);
$assignment = implode("','",$_POST['assignment']);
$exam = implode("','",$_POST['exam']);
$comment = implode("','",$_POST['comment']);
//echo $admissionno. $name. $ca. $assignment. $exam. $comment;
$insert_qry = "INSERT INTO result (id,subject, admissionno, name, ca, assignment, exam, comment)
VALUES('$id', '$subject', '$admissionno', '$name', '$ca', '$assignment', '$exam', '$comment')";
echo $insert_qry;
$result = mysqli_query($connect, $insert_qry);
die('e don do oo');
if($result > 0){
}
}
but I'm getting this error:
Fatal error: Uncaught mysqli_sql_exception: Column count doesn't match value count at row 1 in C:\xampp\htdocs\Malizzay\admin\exam\exam-grade.php:37
Stack trace:
#0 C:\xampp\htdocs\Malizzay\admin\exam\exam-grade.php(37): mysqli_query(Object(mysqli), 'INSERT INTO res...')
#1 {main}
thrown in C:\xampp\htdocs\Malizzay\admin\exam\exam-grade.php on line 37
VALUESlist. You needVALUES (values for row 1), (values for row 2), (values for row3).values (row1), (row2),(row3)notvalues(row1, row2,row3)as it appears you currently have. If you are attempting to store data as CSV in column you also should not do that.values (row1, row2, row3). It's generatingvalues (all ids, all subjects, all admissionno, ...)