我正在尝试使用 php 和 mysql 使用表单添加多个产品,但我对执行这些操作的概念感到困惑,
我期望的输出是,提供一个包含至少十行多个字段的表单,并在其中进行验证,如果没有错误则继续插入。
到目前为止,这是我对单一表单插入的理解:
$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