我试图将输入文本字段的值插入到mysql数据库中,但无济于事!
我要做的是在product_name
表格的product_name
列中输入transactions
值!
我不明白是什么阻止INSERT INTO执行!
有人可以看看这个,让我知道出了什么问题吗?
我甚至没有任何错误,所以我不知道出了什么问题!
<form action="order.php" method="post" name="shoppingcart">
<?php
//We want to include the shopping cart in the email
ob_start();
?>
<table style="border-collapse:collapse;" width="100%" border="1">
<tr>
<th style="border-collapse:collapse;" scope="col"> </th>
<th scope="col">Item Name</th>
<th scope="col">Unit Price</th>
<th scope="col">Qty</th>
<th scope="col">Cost</th>
</tr>
<?php
//Print all the items in the shopping cart
// First we check to see if the form has been submitted
$totalAll = 0;
$total = 0;
$ship = $_POST['ship'];
foreach ($_SESSION['SHOPPING_CART'] as $itemNumber => $item) {
if (isset($_POST['username'])){
//Connect to the database through our include
include_once "config/connect.php";
// Add user info into the database table, claim your fields then values
$sql = "INSERT INTO transactions (firstname, lastname, username, email, price, qty, product_name)
VALUES('$firstname','$lastname','$username','$email','$price','$qty','$product_name')" or die;
$query = mysqli_query($db_conx, $sql);
// Get the inserted ID here to use in the activation email
$id = mysqli_insert_id($db_conx);
}
$totalAll = $totalAll + ($item['qty']*$item['price']);
$total = $totalAll + $ship;
?>
<tr id="item<?php echo $itemNumber; ?>">
<td><a href="order.php?remove=<?php echo $itemNumber; ?>">remove</a></td>
<td><?php echo $item['name']; ?></td>
<td>£<?php echo $item['price']; ?></td>
<td><input name="items_qty[<?php echo $itemNumber; ?>]" type="text" id="item<?php echo $itemNumber; ?>_qty" value="<?php echo $item['qty']; ?>" size="2" maxlength="3" /></td>
<td>£<?php echo $item['qty'] * $item['price']; ?></td>
<input name="price" type="hidden" id="" value="<?php echo $item['price']; ?>" size="2" maxlength="10" />
<input name="qty" type="hidden" id="" value="<?php echo $item['qty']; ?>" size="2" maxlength="10" />
<input name="product_name" type="txt" id="" value="<?php echo $item['name']; ?>" size="2" maxlength="10" />
</tr>
<?php
}
?>
</table>
</div>
<?php $_SESSION['SHOPPING_CART_HTML'] = ob_get_flush(); ?>