我试图从表单中将多个数字(行)加载到数据库中。任何人都可以提供代码帮助吗?
$n = $_POST['txtname'];
foreach ($a as $value) {
$sql = "INSERT INTO Sheet1 VALUES($value)";
答案 0 :(得分:0)
在使用foreach循环之前,需要使用数据初始化数组。
您应该使用以下格式:
//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)";
}