简体   繁体   English

将列表从表单存储到数据库作为数组

[英]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.在使用 foreach 循环之前,您需要用数据初始化一个数组。

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..

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

Sources: http://www.w3schools.com/sql/sql_insert.asp资料来源: http : //www.w3schools.com/sql/sql_insert.asp

http://bbrown.kennesaw.edu/papers/php2.html http://bbrown.kennesaw.edu/papers/php2.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM