Current location: Hot Scripts Forums » Programming Languages » PHP » I need Help with Dropdown list


I need Help with Dropdown list

Reply
  #1 (permalink)  
Old 08-06-03, 03:09 PM
knightjt02 knightjt02 is offline
Newbie Coder
 
Join Date: Aug 2003
Location: WV
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question I need Help with Dropdown list

I have a Dropdown list with Select with 1, 2, 3, 4, after select on of them it bust to refresh the page to what you select but it don't do it. Can you all see what the error is for me? I look over and over i don't see any error or it not the right on i need.
Here All The Code On The Page

PHP 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$updater;
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 
$eurocash$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', '$longdesc', '$prodprice', '$catId')";
        
$result MYSQL_QUERY($query);
        }
        else
        {
        
// This item already exists lets update it.
        
$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$longdesc$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$longdesc$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$longdesc$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 
$cartId$itemId$qty$itemoptions$shortdesc$longdesc$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 
$shipTotal$grandTotal$usdollarcost$usdollar$usdollartotalcost$imageProdFolder$cartId$itemId$qty$itemoptions$shortdesc$longdesc$prodprice$prodtotalcost;
       
$grandTotal 0
        
$totalCost 0;
        
$itemcount 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))
            {
                
// Increment the total cost of all items
                
$prodprice $row["prodprice"];
                
$prodtotalcost number_format($row["qty"] * $row["prodprice"], 2"."",");
                
$totalCost += $row["qty"] * $row["prodprice"];                
                
$itemname $row["itemId"];
              
$totalOption $row["itemoptions"];
                
$optionitem $row["itemId"];
                
$optionitemqty $row["qty"];              
              
                
                
                
$usdollarcost $prodprice $usdollar;
                
$usdollarcost number_format($usdollarcost2"."",");    
                            

</script>
<tr>
<td align="center">
<script language="php">
// this creates the quantity select box for the item.
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>";
}
}
</script> 
Can some one help me?
__________________
Tom
Reply With Quote
  #2 (permalink)  
Old 10-28-03, 08:51 PM
Zeekor Zeekor is offline
New Member
 
Join Date: Oct 2003
Location: Australia
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
From everything i've been reading, this is not possible with PHP. PHP is client side, and run before the HTML page is loaded in the browser, as such it cannot react to butotn presses etc.
There is a very real possibility that I am wrong!
Reply With Quote
  #3 (permalink)  
Old 10-29-03, 11:50 PM
dotbob dotbob is offline
Newbie Coder
 
Join Date: Oct 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
What script did you get this from?
__________________
<img src="http://ebigman.com/image/dotbob_small.gif">Premium Domain Nameshttp://www.dotbob.ebigman.com
Reply With Quote
  #4 (permalink)  
Old 10-30-03, 03:10 AM
Firestorm Firestorm is offline
Newbie Coder
 
Join Date: Oct 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
I have a Dropdown list with Select with 1, 2, 3, 4, after select on of them it bust to refresh the page to what you select but it don't do it. Can you all see what the error is for me? I look over and over i don't see any error or it not the right on i need.

From what I understand, you have a select box, and when you select the option, you want it to be done when you change the selection, i.e, the page reloads with the new information, updated in the database.

alternatively you could use a submit option, which is sometimes easier. onChange is sometimes better used for javascript and client side work.

Quick question, which version of PHP are you using ?

If I could have a clear clarrification of the question, I could rework my possible ideas of your problem
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Formmail Script Fix - Cant display multiple list selections.. zamen PHP 3 05-02-04 09:59 AM
looking for a banned words list cath Script Requests 6 10-29-03 06:18 PM
Help me find a powerful mailing list program abuzerK Script Requests 3 09-17-03 09:32 AM
help finding a mail list server mikestreb PHP 0 09-16-03 11:35 PM
dropdown list from database and with images redspider ASP 4 07-30-03 06:13 AM


All times are GMT -5. The time now is 04:37 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.