I have a form, containing skill name and skill level fields.
This can be dynamically expanded by js so basically they are skill_name[]
and skill_level[]
. The point is, that I would like to insert these into the database
, into separate records.
I have a piece of code, which supposed to do this but not working:
$skill_name = $_POST['skill_name'];
$skill_level = $_POST['skill_level'];
for ($is = 0; $is < count($skill_name); $is++) {
if(!empty($skill_name[$is])) {
$inserting = $db->prepare("insert into position_skills
(`type`,`pid`,`name`,`general`)
values
('skill', :pid, :name, :general");
$inserting ->execute(
array(
':pid' => $last_id,
':name' => $skill_name[$is],
':general' => $skill_level[$is]
));
}
}
The error message is the following:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4' in /home1/xx/public_html/xx/post.php:47 Stack trace: #0 /home1/xx/public_html/xx/post.php(47): PDOStatement->execute(Array) #1 {main} thrown in /home1/xx/public_html/xx/post.php on line 47
The line 47 is the end of the arrays.
I am totally new to PDO, but other insert is working like a charm. What can be the problem? Thanks in advance