我将电子商务网站作为一个学期项目,并尝试将值插入表格中。我有一个包含5列的表,第一个是自动递增的主键。当我尝试插入时,它会在第二列中插入值,同时保留下两个空白并在第五列中插入0。我尝试回显页面上的值以检查它们是否通过URL检索,并且它们可以正常工作。它也没有显示错误。我突出显示了我遇到问题的部分 我的桌子:
这里是整个代码Code.it的一种账单,显示他购买的产品的所有客户详细信息。
<!--Starting session-->
<?php
session_start();
include "adam.php";
?>
<!--Cart session from sign up page hidden fields in login form and sign up form-->
<?php
error_reporting(E_ALL ^ E_NOTICE);//will stop displaying notice errors
$cartoutput="";
$carttotal="";
if(!isset($_SESSION["cart_array"])|| count($_SESSION["cart_array"])<1){
$cartoutput="<h2 align='center' style='color:#ea6a53;'>Your shopping cart is empty</h2>"; }
else{
$i=0;
foreach($_SESSION["cart_array"]as $each_item){
$item_id=$each_item['item_id'];
$quantity=$each_item['quantity'];
$sql=mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1");
while($row=mysql_fetch_array($sql)){
$product_name=$row['product_name'];
$product_cost=$row['price'];
$product_details=$row['details'];
}
$product_total_cost=$product_cost * $quantity;
$carttotal=$product_total_cost+$carttotal;
//Dynamically render table rows
//product name is a link to product page
$cartoutput.='<tr>
<td><a href="prodpage.php?id='.$item_id.'">' . $product_name . '</a></td>
<td>'.$product_details.'</td>
<td>Rs. '.$product_cost.'</td>
<td>'.$each_item['quantity'].'</td>
<td>Rs. '.$product_total_cost.'</td>
</tr>';
$i++;
}
$carttotal="<strong>Cart Total:</strong> <span style='color:black;'>Rs. ".$carttotal."</span>";
}
?>
<!--retrieving user session from last page.php-->
<?php
$cust_id=$_SESSION['id'];
$username=$_SESSION['username'];
$password=$_SESSION['password'];
?>
<!--retrieving shipping,payment cardno variables from url passed from last page.php-->
<?php
if(isset($_GET['payment'])){
global $payment_type,$shipping_type,$card_no;
$payment_type=$_GET['payment'];
$shipping_type=$_GET['shipping'];
$card_no=$_GET['cardno'];
}
?>
<!--Retrieveing customer information for display-->
<?php
$sql=mysql_query("SELECT * FROM customers WHERE id='$cust_id' LIMIT 1");
$row_count=mysql_num_rows($sql);
if($row_count>0){
while($row_count=mysql_fetch_array($sql)){
$username=$row_count['username'];
$email=$row_count['emailid'];
$mobile_no=$row_count['mobileno'];
$address=$row_count['address'];
$user_display='<tr>
<td>'.$username.'</td>
<td>'.$email.'</td>
<td>'.$mobile_no.'</td>
<td>'.$address.'</td>
</tr>';
}
}
?>
<!--Inserting all data in transaction,shipping_payment_details db on confirm button click-->
<?php
***if(isset($_POST['submit'])){
$sql=mysql_query("INSERT INTO shipping_payment_details(customer_id,payment_type,shipping_type,card_no) VALUES('$cust_id','$payment_type','$shipping_type','$card_no')") or die(mysql_error());***
$sql2=mysql_query("INSERT INTO transactions(customer_id,transaction_status)VALUES('$cust_id',1)") or die(mysql_error());
foreach($_SESSION["cart_array"]as $each_item){
$item_id=$each_item['item_id'];
$quantity=$each_item['quantity'];
$sql=mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1");
while($row=mysql_fetch_array($sql)){
$stock=$row["stock"];
}
$stock=$stock-$quantity;
$sql=mysql_query("UPDATE products SET stock='$stock' WHERE id='$item_id' LIMIT 1") or die(mysql_error());
}
unset($_SESSION["cart_array"]);
header("location:feedback.php");
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Confirmation Page</title>
<link rel="stylesheet" href="css/tlfcss.css" />
<link rel="shortcut icon" href="favicon.ico" >
<meta name="viewport" content="width-device-width,initial-scale-1.0">
<link rel="stylesheet" type="text/css" href="css/login Form.css">
<link rel="stylesheet" type="text/css" href="css/product_display_css.css">
</head>
<body>
<div id="big_wrapper">
<header id="topheader">
<!--Logo and menu bar php file-->
<?php include_once "scripts/header file.php"?>
</header>
<section>
<div style="margin-left:24px;font-size:14px;font-family:Segoe UI;text-align:left;">
<h2 style="color:#ea6a53;margin-top:20px;" align="center">Confirmation page</h2>
<!--Customer table display-->
<h4 style="font-family:Segoe UI;font-size:14px;color:#2d2d2d;margin-top:10px;" align="center">Customer Information</h4>
<table width="881" height="78" border="1" align="center" cellpadding="3" dir="ltr" id="table" style="margin-top:20px;margin-left:13px;text-align:center;">
<tr>
<td width="196" height="23" align="center"><strong>Username</strong></td>
<td width="244" align="center"><strong>Email</strong></td>
<td width="166" align="center"><strong>Mobile No</strong></td>
<td width="231" align="center"><strong>Address</strong></td>
</tr>
<?php echo $user_display; ?>
</table>
<!--Cart display-->
<h4 style="font-family:Segoe UI;font-size:14px;color:#2d2d2d;margin-top:24px;" align="center">Your Cart</h4>
<table width="881" height="78" border="1" align="center" cellpadding="3" dir="ltr" id="table" style="margin-top:20px;margin-left:13px;text-align:center;">
<tr>
<td width="158" height="23" align="center"><strong>Product Name</strong></td>
<td width="305" align="center"><strong>Description</strong></td>
<td width="82" align="center"><strong>Price</strong></td>
<td width="118" align="center"><strong>Quantity</strong></td>
<td width="107" align="center"><strong>Total </strong></td>
</tr>
<p><?php echo $cartoutput;?></p>
</table>
<p align="right" style="margin-right:42px;margin-top:8px;color:#ea6a53"><?php echo $carttotal ?></p>
<!--Shipping output-->
<h4 style="font-family:Segoe UI;font-size:14px;color:#2d2d2d;margin-bottom:5px;margin-top:10px;" align="center">Shipping and Payment Details</h4>
<p style="font-family:Segoe UI;font-size:14px;margin-left:15px;"><strong>Payment type:</strong> <?php echo $payment_type; ?></p><br>
<p style="font-family:Segoe UI;font-size:14px;margin-left:15px;"><strong>Shipping type:</strong> <?php echo $shipping_type; ?></p><br>
<p style="font-family:Segoe UI;font-size:14px;margin-left:15px;"><strong>Card No.:</strong> <?php echo $card_no;?></p><br>
<form action="Final page.php" method="post" name="f1" target="_self">
<input name="submit" type="submit" value="Submit" name="submit" id="proceed_button" style="margin-bottom:5px;"></form>
</section>
<?php include_once "scripts/customer footer.php"?>
</div>
</body>
</html>
答案 0 :(得分:1)
您的查询中似乎错过了VALUES
之前的空格:
$sql=mysql_query("INSERT INTO shipping_payment_details(customer_id,payment_type,shipping_type,card_no)VALUES('$cust_id','$payment_type','$shipping_type','$card_no')") or die(mysql_error());
应该是:
$sql=mysql_query("INSERT INTO shipping_payment_details(customer_id,payment_type,shipping_type,card_no) VALUES('$cust_id','$payment_type','$shipping_type','$card_no')") or die(mysql_error());