php - Storing a list from form to database as an array


I'm trying to load a multi numbers(rows) to a database from a form. Anyone can help with the code?

$n = $_POST['txtname'];

foreach ($a as $value) {

$sql = "INSERT INTO Sheet1 VALUES($value)";



You need to initialise an array with the data before using the foreach loop.

You should use the following format:

//Obtain values from form text boxes
$name = $_POST['Name'] //This must match the name input on your form

//Populate values into array
$arrayData = array('$name');  //Can also populate with multiple values..

foreach ($arrayData as $value) {
    $sql = "INSERT into table_name (table_column_name) VALUES($value)";


People are also looking for solutions to the problem: html - PHP mail function doesn't complete sending of e-mail


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.