neomaxin
06-06-2003, 01:48 PM
Hi
Im having problems with a line of code in my Javascript is it not calling a function correctly!!!
I have removed the old function name and replaced it with XXXX Im not sure if the write variables have been specified and which function to call!!! Could anyone tell me the right line of code to replace the red one is in red:
<script language="php">
// this creates the quantity select box for the item.
$itemname = $row["itemId"];
$totalOption = $row["itemoptions"];
printf("<select name=\"$itemname\" onChange=\"XXXX(this, '$totalOption')\">");
for($i = 1; $i <= 5; $i++)
{
echo "<option ";
if($row["qty"] == $i)
{
echo " SELECTED>" . $i . "</option>";
} else {
echo ">" . $i . "</option>";
}
}
// and the delete link
echo "</select><br><br><a href=\"cart.php?action=remove_item&itemId=$itemname&itemoptions=$totalOption\">";
echo "<font color=\"red\" size=\"1\"><b>Remove</b></font></a>";
</script>
<script language="php">
// find out what you want to do with the cart with action variable and act accordinly
global $action, $cartId, $itemId, $qty, $itemoptions, $shortdesc, $longdesc, $prodprice;
if($action == "add_item") {
AddItem();
ShowCart();
}
if($action == "update_item") {
UpdateItem();
ShowCart();
}
if($action == "update_option") {
UpdateItemOption();
ShowCart();
}
if($action == "remove_item") {
RemoveItem();
ShowCart();
}
if($action == "empty_cart") {
EmptyCart();
ShowCart();
}
if(!$action) {
ShowCart();
}
function AddItem()
{
global $prodThumbImg, $cartId, $itemId, $qty, $itemoptions, $shortdesc, $longdesc, $prodprice, $prodtotalcost, $catId;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
$result = mysql_query("select * from cart where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
$row = mysql_fetch_row($result);
$numRows = $row[0];
if($numRows == 0)
{
// This item doesn't exist in the users cart,
// we will add it with an insert query
$query = "INSERT INTO cart VALUES ('$cartId', '$itemId', '$qty', '$itemoptions', '$shortdesc', '$prodThumbImg', '$prodprice', '$catId')";
$result = MYSQL_QUERY($query);
}
else
{
// This item already exists lets update it.
$result = mysql_query("update cart set qty = qty + '$qty' where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
// $result = MYSQL_QUERY($query);
}
}
function UpdateItem()
{
global $cartId, $itemId, $qty, $itemoptions, $shortdesc, $prodThumbImg, $prodprice, $prodtotalcost;
// Updates the quantity of an item in the users cart.
// If the qutnaity is zero, then RemoveItem will be
// called instead
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
mysql_query("update cart set qty = '$qty' where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
}
function UpdateItemOption()
{
global $cartId, $itemId, $qty, $itemoptions, $shortdesc, $prodThumbImg, $prodprice, $prodtotalcost, $prevoption;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
$result = mysql_query("select * from cart where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
$row = mysql_fetch_row($result);
$numRows = $row[0];
if($numRows == 0)
{
// This items size doesn't exist in the users cart,
// we will update old with an insert query
mysql_query("update cart set itemoptions = '$itemoptions' where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$prevoption'");
}
else
{
mysql_query("update cart set qty = qty + '$qty' where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
mysql_query("delete from cart where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$prevoption'");
}
}
function RemoveItem()
{
global $cartId, $itemId, $qty, $itemoptions, $shortdesc, $prodThumbImg, $prodprice, $prodtotalcost;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
mysql_query("delete from cart where cartId like '$cartId' and itemId like '$itemId' and itemoptions like '$itemoptions'");
}
function EmptyCart()
{
global $totalWeight, $cartId, $itemId, $qty, $itemoptions, $shortdesc, $prodThumbImg, $prodprice, $prodtotalcost;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
mysql_query("delete from cart where cartId like '$cartId'");
}
function ShowCart()
{
global $updater, $totalWeight, $shipTotal, $grandTotal, $prodThumbImg, $imageProdFolder, $cartId, $itemId, $qty, $itemoptions, $shortdesc, $prodThumbImg, $prodprice, $prodtotalcost, $cartisdone;
$totalCost = 0;
$itemcount = 0;
$totalWeight = 0;
$shipTotal = 0;
$grandTotal = 0;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
$result = mysql_query("select * from cart where cartId = '$cartId'");
while($row = mysql_fetch_array($result))
{
$prodThumbImg = $row["prodThumbImg"];
// Increment the total cost of all items
$prodtotalcost = ($row["qty"] * $row["prodprice"]);
$totalCost += ($row["qty"] * $row["prodprice"]);
$totalWeight += ($row["qty"] * $row["catId"]);
</script>
Thanks for your help!!!
Im having problems with a line of code in my Javascript is it not calling a function correctly!!!
I have removed the old function name and replaced it with XXXX Im not sure if the write variables have been specified and which function to call!!! Could anyone tell me the right line of code to replace the red one is in red:
<script language="php">
// this creates the quantity select box for the item.
$itemname = $row["itemId"];
$totalOption = $row["itemoptions"];
printf("<select name=\"$itemname\" onChange=\"XXXX(this, '$totalOption')\">");
for($i = 1; $i <= 5; $i++)
{
echo "<option ";
if($row["qty"] == $i)
{
echo " SELECTED>" . $i . "</option>";
} else {
echo ">" . $i . "</option>";
}
}
// and the delete link
echo "</select><br><br><a href=\"cart.php?action=remove_item&itemId=$itemname&itemoptions=$totalOption\">";
echo "<font color=\"red\" size=\"1\"><b>Remove</b></font></a>";
</script>
<script language="php">
// find out what you want to do with the cart with action variable and act accordinly
global $action, $cartId, $itemId, $qty, $itemoptions, $shortdesc, $longdesc, $prodprice;
if($action == "add_item") {
AddItem();
ShowCart();
}
if($action == "update_item") {
UpdateItem();
ShowCart();
}
if($action == "update_option") {
UpdateItemOption();
ShowCart();
}
if($action == "remove_item") {
RemoveItem();
ShowCart();
}
if($action == "empty_cart") {
EmptyCart();
ShowCart();
}
if(!$action) {
ShowCart();
}
function AddItem()
{
global $prodThumbImg, $cartId, $itemId, $qty, $itemoptions, $shortdesc, $longdesc, $prodprice, $prodtotalcost, $catId;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
$result = mysql_query("select * from cart where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
$row = mysql_fetch_row($result);
$numRows = $row[0];
if($numRows == 0)
{
// This item doesn't exist in the users cart,
// we will add it with an insert query
$query = "INSERT INTO cart VALUES ('$cartId', '$itemId', '$qty', '$itemoptions', '$shortdesc', '$prodThumbImg', '$prodprice', '$catId')";
$result = MYSQL_QUERY($query);
}
else
{
// This item already exists lets update it.
$result = mysql_query("update cart set qty = qty + '$qty' where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
// $result = MYSQL_QUERY($query);
}
}
function UpdateItem()
{
global $cartId, $itemId, $qty, $itemoptions, $shortdesc, $prodThumbImg, $prodprice, $prodtotalcost;
// Updates the quantity of an item in the users cart.
// If the qutnaity is zero, then RemoveItem will be
// called instead
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
mysql_query("update cart set qty = '$qty' where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
}
function UpdateItemOption()
{
global $cartId, $itemId, $qty, $itemoptions, $shortdesc, $prodThumbImg, $prodprice, $prodtotalcost, $prevoption;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
$result = mysql_query("select * from cart where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
$row = mysql_fetch_row($result);
$numRows = $row[0];
if($numRows == 0)
{
// This items size doesn't exist in the users cart,
// we will update old with an insert query
mysql_query("update cart set itemoptions = '$itemoptions' where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$prevoption'");
}
else
{
mysql_query("update cart set qty = qty + '$qty' where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$itemoptions'");
mysql_query("delete from cart where cartId = '$cartId' and itemId = '$itemId' and itemoptions = '$prevoption'");
}
}
function RemoveItem()
{
global $cartId, $itemId, $qty, $itemoptions, $shortdesc, $prodThumbImg, $prodprice, $prodtotalcost;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
mysql_query("delete from cart where cartId like '$cartId' and itemId like '$itemId' and itemoptions like '$itemoptions'");
}
function EmptyCart()
{
global $totalWeight, $cartId, $itemId, $qty, $itemoptions, $shortdesc, $prodThumbImg, $prodprice, $prodtotalcost;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
mysql_query("delete from cart where cartId like '$cartId'");
}
function ShowCart()
{
global $updater, $totalWeight, $shipTotal, $grandTotal, $prodThumbImg, $imageProdFolder, $cartId, $itemId, $qty, $itemoptions, $shortdesc, $prodThumbImg, $prodprice, $prodtotalcost, $cartisdone;
$totalCost = 0;
$itemcount = 0;
$totalWeight = 0;
$shipTotal = 0;
$grandTotal = 0;
include "adminshop/config/shop_db.php";
$db = mysql_connect($host, $dbuser, $dbpass);
mysql_select_db($dbase,$db);
$result = mysql_query("select * from cart where cartId = '$cartId'");
while($row = mysql_fetch_array($result))
{
$prodThumbImg = $row["prodThumbImg"];
// Increment the total cost of all items
$prodtotalcost = ($row["qty"] * $row["prodprice"]);
$totalCost += ($row["qty"] * $row["prodprice"]);
$totalWeight += ($row["qty"] * $row["catId"]);
</script>
Thanks for your help!!!