这是我第一次使用多个选择选项并在表单中添加更多字段功能。我有这个表格,我可以输入多个serialNumber,并相应地添加多个配件和数量。但唯一第一个选择的serialNumber和附件(和数量)保存在我的数据库中。
所以这是我的HTML表单:
<form id="form1" name="form1" method="post" action="requisitionForm_process.php" onsubmit="return validateForm()" >
<div class="form-group">
<label for="DONO">DO. Number: </label>
<input class="form-control" id="DONO" name="DONO" placeholder="Place DO. Number Here" type="text"/>
</div>
<div class="form-group">
<label for="requestby">Request By: </label>
<select class="form-control" id="empCode" name="empCode">
<?php while ($row = mysqli_fetch_array($resultR)):;?>
<option value = <?php echo $row ['empCode']; ?>><?php echo $row ['empCode']; echo ":"; echo $row ['empName'];?></option>
<?php endwhile;
?>
</select>
</div>
<div class="form-group">
<label for="requestby">Customer: </label>
<select class="form-control" id="customerCode" name="customerCode">
<?php while ($row = mysqli_fetch_array($resultC)):;?>
<option value = <?php echo $row ['customerCode']; ?>><?php echo $row ['customerCode']; echo ":"; echo $row ['customerName'];?></option>
<?php endwhile;
?>
</select>
</div>
<div class="form-group"> <!-- Date input -->
<label class="control-label" for="dateOUT">Date:</label>
<input class="form-control" id="dateOUT" name="dateOUT" placeholder="DD/MM/YYY" type="text"/>
</div>
<div class="form-group">
<label for="categoryCode">Category: </label>
<select class="form-control" id="categoryCode" name="categoryCode">
<option value="new"> New Installation</option>
<option value="re">Re-installation</option>
</select>
</div>
<div class="form-group">
<label for="categoryCode">Product: </label>
<select class="form-control" id="productCode" name="productCode">
<?php while ($row = mysqli_fetch_array($result)):;?>
<option value = <?php echo $row ['productCode']; ?>><?php echo $row ['productCode']; echo ":"; echo $row ['productName'];?></option>
<?php endwhile;
?>
</select>
</div>
<div class="form-group">
<label for="serialNumber">Serial Number:</label><br>
<select id="serialNumber" name="serialNumber[]" multiple class="form-control" >
<?php while ($row = mysqli_fetch_array($resultSe)):;?>
<option value = <?php echo $row ['serialNumber']; ?>><?php echo $row ['serialNumber'];?></option>
<?php endwhile;?>
</select>
</div>
<table class="table table-bordered" id="item_table">
<tr>
<th>Select Accessories</th>
<th>Enter Quantity</th>
<th><button type="button" name="add" class="btn btn-success btn-sm add"><span class="glyphicon glyphicon-plus"></span></button></th>
</tr>
</table>
<div class="form-group">
<input type="button" class="btn" id="checkBtn" name="return" value="Back" onClick="javascript: window.history.back(-1)";>
<input class="btn btn-primary" type="reset" value="Reset">
<input align="right" type="submit" class="btn btn-info" value="Submit Button">
</div>
</div>
</form>
这是我的PHP流程:
<?php
if(isset($_POST["serialNumber"]))
{
$serialNumber = '';
foreach($_POST["serialNumber"] as $row)
{
$serialNumber .= $row . ', ';
}
$serialNumber = substr($serialNumber, 0, -2);
if(isset($_POST["categoryCode"]))
{
$connect = new PDO("mysql:host=localhost;dbname=ims", "root", "");
$DONO = $_POST["DONO"];
$empCode = $_POST["empCode"];
$customerCode = $_POST["customerCode"];
$categoryCode = $_POST["categoryCode"];
$productCode = $_POST["productCode"];
$dateOUT = date('Y-m-d', strtotime($_POST['dateOUT']));
for($count = 0; $count < count($_POST["accID"]); $count++)
{
$query = "INSERT INTO requisition (DONO, empCode, customerCode, dateOUT, categoryCode, productCode, serialNumber, quantityAcc, accID) VALUES (:DONO, :empCode, :customerCode, :dateOUT, :categoryCode, :productCode, :serialNumber, :quantityAcc, :accID) ";
$statement = $connect->prepare($query);
$statement->execute(
array(
':DONO' => $DONO,
':empCode' => $empCode,
':customerCode' => $customerCode,
':dateOUT' => $dateOUT,
':categoryCode' => $categoryCode,
':productCode' => $productCode,
':serialNumber' => $serialNumber,
':quantityAcc' => $_POST["quantityAcc"][$count],
':accID' => $_POST["accID"][$count]
)
);
}
$result = $statement->fetchAll();
if(isset($result))
{
echo 'ok';
}
}
}
?>
答案 0 :(得分:0)
module.js:549
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
module.js:549
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
在我无法使用html之前用这个替换yor循环。