Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12

Thread: PHP no updating

  1. #1
    New Coder
    Join Date
    Jun 2003
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP no updating

    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

  • #2
    Regular Coder
    Join Date
    May 2002
    Location
    London, England
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why are you using <script> and </script> tags?

    Use <? and ?> like so:

    PHP Code:
    <?
    // 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
    Jeewhizz - MySQL Moderator
    http://www.sitehq.co.uk
    PHP and MySQL Hosting

  • #3
    New Coder
    Join Date
    Jun 2003
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The same problem still occurs!!!

  • #4
    New Coder
    Join Date
    Jun 2003
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try adding this item to your cart then in the cart try changing the quantity!!!

    http://www.ukcruisescene.com/shop/in...on-mou-5.6-001

  • #5
    New Coder
    Join Date
    Jun 2003
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Its an object expected error if that helps???

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    If you're getting errors in your taskbar, then it ain't a php error

  • #7
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    That's not a PHP error. That's a javascript error. I will move this to the Javascript forum...
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #8
    New Coder
    Join Date
    Jun 2003
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks so can anyone help me???

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #10
    New Coder
    Join Date
    Jun 2003
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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???
    Last edited by neomaxin; 06-06-2003 at 02:05 PM.

  • #11
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #12
    New Coder
    Join Date
    Jun 2003
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •