gpt4 book ai didi

php - 无法插入到 php 中的表中,从 url 检索值

转载 作者:行者123 更新时间:2023-11-29 03:01:51 25 4
gpt4 key购买 nike

我正在制作一个电子商务网站作为一个学期项目,同时尝试将值插入到表中。我有一个包含 5 列的表,第一列是自动递增的主键。当我尝试插入时,它会在第二列中插入值,同时将接下来的两列留空并在第五列中插入 0。我尝试回显页面上的值以检查它们是否正在通过 url 检索,并且它们有效。它也没有显示错误。我已经突出显示了我遇到问题的部分。
我的 table :

enter image description here

这是完整的代码 Code。它是一种显示所有客户详细信息及其购买的产品的账单。

    <!--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.&nbsp;'.$product_cost.'</td>
<td>'.$each_item['quantity'].'</td>
<td>Rs.&nbsp;'.$product_total_cost.'</td>
</tr>';
$i++;
}
$carttotal="<strong>Cart Total:</strong>&nbsp;<span style='color:black;'>Rs.&nbsp;".$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>&nbsp;<?php echo $payment_type; ?></p><br>
<p style="font-family:Segoe UI;font-size:14px;margin-left:15px;"><strong>Shipping type:</strong>&nbsp;<?php echo $shipping_type; ?></p><br>
<p style="font-family:Segoe UI;font-size:14px;margin-left:15px;"><strong>Card No.:</strong>&nbsp;<?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>

最佳答案

您似乎在查询中的 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());

关于php - 无法插入到 php 中的表中,从 url 检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22426931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com