Jump to content

Recommended Posts

I've just started working on my first PHP / MySQL / web page, but I've ran into a snag. I'm using XAMPP & Dreamweaver CS4. I'm building a small site that will allow me to have several different people log in to make purchases. Each person will have their own discount rate. I've got the log in page built with PHP. A MySQL database that holds their names, email/Password, & discount multipliers. My problem is, how can I make it, so that when someone logs in, the prices are showing that individual's discounted price? The way I've got it now the discount keeps pulling from the first row in the table, regardless of who I log in as. Thanks for any help or tips that you might could get me.

thanks

Link to comment
https://forums.phpfreaks.com/topic/213139-very-newb-question/
Share on other sites

Without fully knowing what you are working with it is hard to say how to fix this, but I will give you my input on how you could do this. Assuming you have a table with discount rates you could in the users table store the id to the discount rate that the user that is logged in gets. Then when the user is logged in you could then pull there discount rate id from there table then query the table with the rates in it looking for that id and thereby getting the rate. Then you could use that rate for the calculations from there.

Link to comment
https://forums.phpfreaks.com/topic/213139-very-newb-question/#findComment-1109918
Share on other sites

Here is my source, with the pertinent info at the bottom in the Body tag, using an example of Shoes. What I'm trying to do is, if the price of the shoes is, say $30.00, then it could somehow multiply the product's price by that individual salesman's "multiplier" thereby displaying his discounted rate. My problem is, that for some reason, it isn't pulling the"multiplier" from the table of whoever is logged in, it's just pulling it from the first record in the database.

 

<?php require_once('Connections/connRegister.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "fail.htm";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?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;
}
}

mysql_select_db($database_connRegister, $connRegister);
$query_Recordset1 = "SELECT * FROM register";
$Recordset1 = mysql_query($query_Recordset1, $connRegister) 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>Untitled Document</title>
</head>

<body>
<h1>Shopping Cart
</h1>
<h2>Sales Items</h2>
<p> </p>
<p>Shoes $<?php echo $row_Recordset1['MULTIPLIER'] * 30; ?></p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Link to comment
https://forums.phpfreaks.com/topic/213139-very-newb-question/#findComment-1109920
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.