为什么我的数据库获得相同的用户ID?

时间:2016-05-23 05:49:19

标签: php

我只是想知道为什么我的数据库会持续获得相同的用户ID 即使我与不同的用户登录

here is my users table

here is my cart info...

cartID 54是'reinhart'用户 cartID 55是'caspe'用户

但它们在购物车表中具有相同的用户ID。

当我尝试从productinfo.php

插入新数据条目时发生了这种情况

这是我的代码

productinfouser.php

<?php @session_start(); ?>
<?php require_once('Connections/localhost.php'); ?>
<?php
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"] == "productform.php")) {
  $insertSQL = sprintf("INSERT INTO cart (name, brand, category, price, userid) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['brand'], "text"),
                       GetSQLValueString($_POST['category'], "text"),
                       GetSQLValueString($_POST['price'], "text"),
                       GetSQLValueString($_POST['userid_hiddenfield'], "text"));

  mysql_select_db($database_localhost, $localhost);
  $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());

  $insertGoTo = "shoppingcart.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

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;
}
}

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;
}
}

mysql_select_db($database_localhost, $localhost);
$query_productinfo = "SELECT * FROM firstci_ecommercedb.product";
$productinfo = mysql_query($query_productinfo, $localhost) or die(mysql_error());
$row_productinfo = mysql_fetch_assoc($productinfo);
$totalRows_productinfo = mysql_num_rows($productinfo);

mysql_select_db($database_localhost, $localhost);
$query_Recordset1 = "SELECT * FROM users";
$Recordset1 = mysql_query($query_Recordset1, $localhost) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>productinfo</title>
<link href="css/mystyle.css" rel="stylesheet" type="text/css" />
<link href="css/productinfostyle.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
</style>
</head>
<body>
<div id="container">
<div id="header"></div>
     <!-- *************************** MENU -->
    <div id="menu">
        <ul>
            <li><a href="#">Order</a></li>
            <li><a href="#">Cart</a></li>
            <li><a href="#">Home</a></li>
        </ul>
    </div>
    <!-- *************************** CATEGORY -->
    <div id="category"><ul>
            <li><a href="computers.php"><img src="images/menudesktop.png" width="333" height="100" border="0"/></a></li>
            <li><a href="laptops.php"><img src="images/menulaptop.png" width="333" height="100" alt=""/></a></li>
            <li><a href="mobiles.php"><img src="images/menumobile.png" width="333" height="100" alt=""/></a></li>
        </ul>
  </div>
  <!-- *************************** BRAND -->
    <div id="brand">
        <ul>
            <li><a href="#">Intel</a></li>
            <li><a href="#">Lenovo</a></li>
            <li><a href="#">Samsung</a></li>
            <li><a href="#">Dell</a></li>
            <li><a href="#">Cherry Mobile</a></li>
            <li><a href="#">Apple</a></li>
        </ul>
    </div>

  <!-- *************************** MAINBODY -->
    <div id="mainbody">
        <form id="productform" name="productform.php" method="POST" action="<?php echo $editFormAction; ?>">
          <div id="itemimg"><img src="images/cart.png" /></div>
            <div id="itemdesc"><br />
              <br />
              <table width="600" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="301"><table width="300" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><?php echo $_POST['name']; ?>
                      <input type="hidden" value="<?php echo $_POST['name']; ?>" name="name" /></td>
                    </tr>
                    <tr>
                      <td><?php echo $_POST['brand']; ?>
                      <input type="hidden" value="<?php echo $_POST['brand']; ?>" name="brand" /></td>
                    </tr>
                    <tr>
                      <td><?php echo $_POST['category']; ?>
                      <input type="hidden" value="<?php echo $_POST['category']; ?>" name="category" /></td>
                    </tr>
                    <tr>
                      <td><?php echo $_POST['price']; ?>
                      <input type="hidden" value="<?php echo $_POST['price']; ?>" name="price" /></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td><input type="submit" name="submit" id="submit" value="Add to Cart" />
                      <input name="userid_hiddenfield" type="hidden" id="userid_hiddenfield" value="<?php echo $row_Recordset1['userid']; ?>" /></td>
                    </tr>
                    <tr>
                      <td><input name="hfname" type="hidden" id="hfname" value="<?php echo $row_productinfo['name']; ?>" />
                      <input name="brandhf" type="hidden" id="brandhf" value="<?php echo $row_productinfo['brand']; ?>" />
                      <input name="cateagoryhf" type="hidden" id="cateagoryhf" value="<?php echo $row_productinfo['category']; ?>" />
                      <input name="pricehf" type="hidden" id="pricehf" value="<?php echo $row_productinfo['price']; ?>" />
                      <input name="descriptionhf" type="hidden" id="descriptionhf" value="<?php echo $row_productinfo['description']; ?>" /></td>
                    </tr>
                  </table></td>
                  <td width="299"><?php echo $_POST['description']; ?>
                  <input type="hidden" value="<?php echo $_POST['description']; ?>" name="description" /></td>
                </tr>
              </table>
            </div>
            <input type="hidden" name="MM_insert" value="productform.php" />
        </form>
  </div>
  <!-- *************************** FOOTER -->
    <div id="footer"><p>Runts & Giants</p></div>

</div>
</body>
</html>
<?php
mysql_free_result($productinfo);

mysql_free_result($Recordset1);
?>

这是我的产品表结构

enter image description here

0 个答案:

没有答案