【发布时间】:2018-10-25 11:44:23
【问题描述】:
请我需要使用 post submit 将表数据的值插入到数据库中,但我似乎没有正确...代码不完整,我只需要任何人让我通过post提交数据。
<?php
if(isset($_POST['submit'])){
$title = $_POST[$product['title']];
$slug = $_POST[$product['slug']];
$slug = $_POST[$product['description']];
$quantity = $_POST[$product['quantity']];
$subTotal = $_POST[number_format($total, 2) ];
}
?>
// i guess my post submit is wrong...
<table class="table table-striped">
<tr>
<th colspan="7"><h3 class="text-center">Order details</h3></th>
</tr>
<tr class="btn bg-success">
<th>Title</th>
<th>Slug</th>
<th>Description</th>
</tr>
<form method="post" action="cart.php">
<tr>
<td class="text-info" name="title"><?php echo $product['title']; ?></td>
<td class="text-info"><?php echo $product['slug']; ?> </td>
<td class="text-info"><?php echo $product['description']; ?> </td>
<input type="submit" name="submit" class="btn btn-success text-right" value="Checkout" onClick="return confirm('you will be redirected .....');" /> <!-- submit button -->
</table>
All i need is to post to the database after clicking the submit button. Thank You.
【问题讨论】:
-
显示任何错误?你能打印出这些值还是空的?
-
你的输入标签在哪里?
-
正在提交的
<form>将发布表单元素的内容,例如<input>或<select>等。您似乎没有这些内容。您甚至没有完整的表单(您永远不会关闭</form>元素)。而且表格一开始看起来格式不正确。 -
@David 为了清楚起见,我不得不删除一些代码......我的主要问题是发布
并发布到数据库中。 -
@sanmexm:如果您删除了表单元素,那么这确实是问题所在。您的表单没有输入、选择、文本区域等来保存任何表单值。您似乎成功地发布了一个空表单。