...

View Full Version : PHP no updating



neomaxin
06-03-2003, 11:21 PM
Can anyone help me I am fairly new to php and am trying to get my online shop working!!!


Im having trouble with my quantity list box in my cart!!! When another quantity is selected nothing happens and the database doesnt get updated!!! Plus the status bar on browser says that there is an error on the page when a new quantity is selected!!! The code is as follows




<script language="php">
// this creates the quantity select box for the item.
$itemname = $row["itemId"];
$totalOption = $row["itemoptions"];

printf("<select name=\"$itemname\" onChange=\"UpdateQty(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>




Thanks for any help you can give me

Jeewhizz
06-04-2003, 10:32 AM
Why are you using <script> and </script> tags?

Use <? and ?> like so:



<?
// this creates the quantity select box for the item.
$itemname = $row["itemId"];
$totalOption = $row["itemoptions"];

printf("<select name=\"$itemname\" onChange=\"UpdateQty(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>";
?>


Jee

neomaxin
06-04-2003, 10:40 AM
The same problem still occurs!!!:confused:

neomaxin
06-04-2003, 10:52 AM
try adding this item to your cart then in the cart try changing the quantity!!!

http://www.ukcruisescene.com/shop/index.php?prodID=mon-mou-5.6-001

neomaxin
06-04-2003, 12:03 PM
Its an object expected error if that helps???

Nightfire
06-05-2003, 10:37 PM
If you're getting errors in your taskbar, then it ain't a php error

Spookster
06-05-2003, 10:39 PM
That's not a PHP error. That's a javascript error. I will move this to the Javascript forum...

neomaxin
06-06-2003, 11:05 AM
Thanks so can anyone help me???

Garadon
06-06-2003, 11:56 AM
this line from u code:
printf("<select name=\"$itemname\" onChange=\"UpdateQty(this, '$totalOption')\">");

makes this line on the client:

<select name="mon-mou-5.6-001" onChange="UpdateQty(this, '')">


only problem is you try to run this function:
UpdateQty(this, '')

which I can't find in you code, lack of the function that u call will raise that error you get

neomaxin
06-06-2003, 01:01 PM
is there anyway i can just take out the function???

or do i need to write an function to update the quantity in the cart???

Garadon
06-06-2003, 01:07 PM
printf("<select name=\"$itemname\" >");

that will remove the function call but eh I assume u wrote the call there in the first place for some reason lol so perhaps removing it will not be so wise?

neomaxin
06-06-2003, 01:16 PM
here are all my functions in the php cart page and also the quantity list box!!! So what should i put in that like??? Thanks

CODE:

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

<tr>
<td align="center">
<script language="php">

$itemname = $row["itemId"];
$totalOption = $row["itemoptions"];

printf("<select name=\"$itemname\" onChange=\"UpdateItemOption(this, '$totalOption')\">");
for($i = 1; $i <= 5; $i++)
{
echo "<option ";
if($row["qty"] == $i)
{
echo " SELECTED>" . $i . "</option>";
} else {
echo ">" . $i . "</option>";
}
}

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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum