如何使用提交按钮导出数据

时间:2019-04-22 00:13:11

标签: php html

在其他情况下,我使用带有操作键的“提交”按钮重定向到另一个页面,但从未使用过从数据库中拉出循环。我应该怎么做?第一部分来自原始页面,第二部分来自重定向页面以存储在数据库中。

<form action="insertorder.php" method="post">
<input type="submit" class="btn btn-dark" value="Submit">
<?php while ($row = $result->fetch_assoc()) :?>

<tr>
    <td name="Item_ID"><?=$row["item_id"]?></td>
    <td name="name"><?=$row["ITEM_NAME"]?></td>
    <td name="suggested_qty"><?=$row["suggested_qty"]?></td>
    <td  name="price" class="pricetd"><?=$row["Price_item"]?></td>
    <td>
    <input type="text" name="editedvalues[]" class="qtyinput" value="<?=$row["suggested_qty"]?>" />
    </td>
    <td><input name='result' class="resultinput" /></td>
</tr>

<?php endwhile?>

</table>
</form>

////////////////////////
$ItemID = mysqli_real_escape_string($conn,$_POST['Item_ID']);
$ItemName = mysqli_real_escape_string($conn,$_POST['name']);
$SuggQty = mysqli_real_escape_string($conn,$_POST['suggested_qty']);
$Price = mysqli_real_escape_string($conn,$_POST['price']);
$OrderQty = mysqli_real_escape_string($conn,$_POST['editedvalues[]']);
$TotalCost = mysqli_real_escape_string($conn,$_POST['result']);

$sql = "INSERT INTO ms_order (item_id, item_name, suggested_qty, price_item, order_ouantity, total) VALUES ('$ItemID', '$ItemName', '$SuggQty', '$Price', '$OrderQty', $TotalCost)";

if ($conn->query($sql) === TRUE) {
    echo "Submitted! Click here to return to Commodity Page:";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

0 个答案:

没有答案