多SQL插入&;php中的表单验证
我正在尝试使用php和mysql使用表单进行多产品添加,但我对这样做的概念感到困惑 我的预期输出是,提供一个表单,其中至少有十行多个字段需要填充,并在这些字段之间进行验证,如果没有错误,则继续插入 以下是我到目前为止对单表单插入的理解:多SQL插入&;php中的表单验证,php,mysql,validation,insertion,Php,Mysql,Validation,Insertion,我正在尝试使用php和mysql使用表单进行多产品添加,但我对这样做的概念感到困惑 我的预期输出是,提供一个表单,其中至少有十行多个字段需要填充,并在这些字段之间进行验证,如果没有错误,则继续插入 以下是我到目前为止对单表单插入的理解: $add_errors = array(); //if there is a post request if ($_SERVER['REQUEST_METHOD'] == 'POST') { // do some validation if (em
$add_errors = array();
//if there is a post request
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// do some validation
if (empty($_POST['name'])) {
$add_errors['name'] = 'Please enter the name!';
}
if (empty($_POST['description'])) {
$add_errors['description'] = 'Please enter the description!';
}
if (empty($add_errors)) { // If everything's OK.
//do the insertion
$q = 'INSERT INTO ........')';
}
}//end of form submission
echo '<form action="product_add.php" enctype="multipart/form-data" method="post" accept-charset="utf-8">';
echo '<input type=..... name=...... id=.....>';
echo '<input type=..... name=...... id=.....>';
echo '<input type=..... name=...... id=.....>';
echo '</form';
//this form is only a single row with multiple column(field) ,I am trying to make it into multiple column
$add_errors=array();
//如果有post请求
如果($\u服务器['REQUEST\u METHOD']=='POST'){
//做一些验证
if(空($_POST['name'])){
$add_errors['name']=“请输入名称!”;
}
if(空($_POST['description'])){
$add_errors['description']=“请输入说明!”;
}
if(空($add_errors)){//如果一切正常。
//插入
$q='插入……。';
}
}//表格提交结束
回声';
回声';
回声';
回声';
echo'我将重写上面的代码…我将在这里重写它:
<?php
$rows = 10; // rows desired.
//if there is a post request
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
while($i < $rows){
if (empty($_POST['description'.$i])) {
$add_errors['description'.$i] = 'Please enter the description!';
}
// more error checking if needed...
++$i;
}
if (empty($add_errors)) { // If everything's OK.
//do the insertion
$q = 'INSERT INTO ........')';
}
}//end of form submission
echo '<form action="product_add.php" enctype="multipart/form-data" method="post" accept-charset="utf-8">';
$i = 0;
while($i < $rows){
echo '<input type=..... name="description'.$i.'" id=.....>';
++$i;
}
echo '</form';
?>
尝试类似的方法…(我的代码可能有一两个错误,因为我只是在这里写的,没有测试),但这是一般的想法。=) 谢谢你们给我指明了正确的方向。我想我大概明白你的大概意思了()