关于购物车已经存在商品,自+1进数据库的问题,
小弟做了一个购物车,已经能够写进数据库,并且能够读取了,但是我点击购买同一个商品,他不是在同一个商品的数量上+1,而是又插入了一条记录,请问高手们应该如何改?以下是小弟做...
小弟做了一个购物车,已经能够写进数据库,并且能够读取了,但是我点击购买同一个商品,他不是在同一个商品的数量上+1,而是又插入了一条记录,请问高手们应该如何改?以下是小弟做的代码:
<?php require_once('Connections/conn.php'); ?>
<?php
session_start();
if($_SESSION['MM_Username']==""){
echo "<script>alert('请先登录!');window.location.href=denglu.php'</script>";
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO gouwuche (g_bookname, g_bookprice, g_username, b_bookid) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['b_name'], "text"),
GetSQLValueString($_POST['b_price'], "text"),
GetSQLValueString($_POST['g_username'], "text"),
GetSQLValueString($_POST['b_bookid'], "text"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
$insertGoTo = "gouwu.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_Rs1 = "-1";
if (isset($_GET['b_bookid'])) {
$colname_Rs1 = $_GET['b_bookid'];
}
mysql_select_db($database_conn, $conn);
$query_Rs1 = sprintf("SELECT * FROM bookbiao WHERE b_bookid = %s", GetSQLValueString($colname_Rs1, "int"));
$Rs1 = mysql_query($query_Rs1, $conn) or die(mysql_error());
$row_Rs1 = mysql_fetch_assoc($Rs1);
$totalRows_Rs1 = mysql_num_rows($Rs1);
$query_rs3_update="update gouwuche set g_sellnum=g_sellnum+1 where b_bookid=$colname_rs1";
$rs3_update=mysql_query($query_rs3_update);// 这一部分是我做的那个自增长的代码
?> 展开
<?php require_once('Connections/conn.php'); ?>
<?php
session_start();
if($_SESSION['MM_Username']==""){
echo "<script>alert('请先登录!');window.location.href=denglu.php'</script>";
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO gouwuche (g_bookname, g_bookprice, g_username, b_bookid) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['b_name'], "text"),
GetSQLValueString($_POST['b_price'], "text"),
GetSQLValueString($_POST['g_username'], "text"),
GetSQLValueString($_POST['b_bookid'], "text"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
$insertGoTo = "gouwu.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_Rs1 = "-1";
if (isset($_GET['b_bookid'])) {
$colname_Rs1 = $_GET['b_bookid'];
}
mysql_select_db($database_conn, $conn);
$query_Rs1 = sprintf("SELECT * FROM bookbiao WHERE b_bookid = %s", GetSQLValueString($colname_Rs1, "int"));
$Rs1 = mysql_query($query_Rs1, $conn) or die(mysql_error());
$row_Rs1 = mysql_fetch_assoc($Rs1);
$totalRows_Rs1 = mysql_num_rows($Rs1);
$query_rs3_update="update gouwuche set g_sellnum=g_sellnum+1 where b_bookid=$colname_rs1";
$rs3_update=mysql_query($query_rs3_update);// 这一部分是我做的那个自增长的代码
?> 展开
1个回答
2012-11-06
展开全部
太专业了,还得是到专业一些的论坛上才方便找到高手。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询