PDA

View Full Version : Java function code line


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!!!

neomaxin
06-06-2003, 06:06 PM
both of these bits of code are in my cart.php!!!

arnyinc
06-06-2003, 06:36 PM
This is a javascript forum. You aren't going to find that everyone is an expert in PHP and javascript.

"I have removed the old function name and replaced it with XXXX"

Why did you do that? Was there a problem with the old function?

"Im not sure if the write variables have been specified and which function to call!!!"

What do you need the function to do? I am confused because usually php code goes between <? ?> and javascript goes between <script></script>.

The best thing to do is to process the page on the server, then view the source and troubleshoot it that way. Then it is only a javascript problem that you are troubleshooting.

neomaxin
06-06-2003, 07:50 PM
Originally posted by arnyinc
This is a javascript forum. You aren't going to find that everyone is an expert in PHP and javascript.

"I have removed the old function name and replaced it with XXXX"

Why did you do that? Was there a problem with the old function?

"Im not sure if the write variables have been specified and which function to call!!!"

What do you need the function to do? I am confused because usually php code goes between <? ?> and javascript goes between <script></script>.

The best thing to do is to process the page on the server, then view the source and troubleshoot it that way. Then it is only a javascript problem that you are troubleshooting.


I put XXXX in because it wasnt calling anything that was the error i was getting throught the browser(object expected)!!! It is a list box for the quantity of an item in a cart, so i want it to call the an update function from the second piece of coding!!!


basically all i want to know is how i should set out the line hilighted i red to run an update function in the second piece of code???

Garadon
06-06-2003, 09:04 PM
make a form like the one u use to add the item in the first place with hidden variable and all.('the one need in the php updateItemFunction()')


<form action="cart.php" method="post">


HIDDEN FIELDS

printf("<select name=\"$itemname\" onChange=\"submit();\">");
</form>

neomaxin
06-07-2003, 11:30 AM
i have no idea how to do this can anyone give me an example?

missing-score
06-07-2003, 09:34 PM
Just to speculate, you can use:

<script langauge="php" type="text/php">
php code
</script>

to run php code...