Entering an array of values into mysql table

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 7
Joined: Thu Aug 31, 2017 3:48 am

Mon Sep 18, 2017 3:24 am

I have two html tables with initially one row each, 3 cols (one input type text, two inputs type number). The user can add more rows if necessary to both. When submitted, each col input has the same name and a [] indicating an array. For the first table, each col1 input is an element in an array, in the second, each col1 input is a comma separated array.
I came across this on stackoverflow

Code: Select all

$sql = "INSERT INTO questions (`question_name`) VALUES (:question_name)";
// prepare a stamement only once
$stmt = $db->prepare($sql);
$stmt->bindParam(':question_name', $question_name);
// iterate over your POST[question_name] array
foreach ($_POST['question_name'] as $question_name) {
How do I or can I adapt this for multiple values?

Post Reply