www.webdeveloper.com
Results 1 to 7 of 7

Thread: quantity in shopping cart ! need some help

  1. #1
    Join Date
    Feb 2014
    Posts
    11

    quantity in shopping cart ! need some help

    i post one post before and pliz admins delite it , i didnt get answer at all i think that i didnt explain problem so i will try again ,

    i bild litle webpage and seling some staffs there but in my shopingcart when visiter enter some big number shoping cart calculate price for it even there is no that much products in DB ... so i need just a litle part of code that will "take a look in DB in fild lager" and if there is no that much what visitor enter to get message that there is no that much products right now ! here is code of shoping cart

    PHP Code:
    <?php
        
    include("includes/db.php");
        include(
    "includes/functionss.php");
        include(
    "languages/frontend.ch.php");
            
    //$db = $_SESSION['database'];
        
    if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0){
            
    remove_product($_REQUEST['pid']);
        }
        else if(
    $_REQUEST['command']=='clear'){
            unset(
    $_SESSION['cart']);
        }
        else if(
    $_REQUEST['command']=='update'){
            
    $max=count($_SESSION['cart']);
            for(
    $i=0;$i<$max;$i++){
                
    $pid=$_SESSION['cart'][$i]['productid'];
                
    $q=intval($_REQUEST['product'.$pid]);
                if(
    $q>&& $q<=500){
                    
    $_SESSION['cart'][$i]['qty']=$q;
                }
                else{
                    
    $msg='Some proudcts not updated!, quantity must be a number between 1 and 999';
                }
            }
        }

    ?>
    this is functions .... i add a function to get how much products are in DB but i dont know how to inplement it on shoping cart

    PHP Code:
    <?php
        
    function get_product_name($pid){
            
    $result=mysql_query("select Art from druckfederi where artnr=$pid") or die("select Art from druckfederi where artnr=$pid"."<br/><br/>".mysql_error());
            
    $row=mysql_fetch_array($result);
            return 
    $row['Art'];
        }
        function 
    get_price($pid){
            
    $result=mysql_query("select cena from druckfederi where artnr=$pid") or die("select art from products where artnr=$pid"."<br/><br/>".mysql_error());
            
    $row=mysql_fetch_array($result);
            return 
    $row['cena'];
        }
        function 
    get_stanje($pid){
            
    $result=mysql_query("select stanje from druckfederi where artnr=$pid") or die("select art from products where artnr=$pid"."<br/><br/>".mysql_error());
            
    $row=mysql_fetch_array($result);
            return 
    $row['stanje'];
        }
        function 
    remove_product($pid){
            
    $pid=intval($pid);
            
    $max=count($_SESSION['cart']);
            for(
    $i=0;$i<$max;$i++){
                if(
    $pid==$_SESSION['cart'][$i]['productid']){
                    unset(
    $_SESSION['cart'][$i]);
                    break;
                }
            }
            
    $_SESSION['cart']=array_values($_SESSION['cart']);
        }
        function 
    get_order_total(){
            
    $max=count($_SESSION['cart']);
            
    $sum=0;
            for(
    $i=0;$i<$max;$i++){
                
    $pid=$_SESSION['cart'][$i]['productid'];
                
    $q=$_SESSION['cart'][$i]['qty'];
                
    $price=get_price($pid);
                
    $sum+=$price*$q;
            }
            return 
    $sum;
        }
        function 
    addtocart($pid,$q){
            if(
    $pid<or $q<1) return;
            
            if(
    is_array($_SESSION['cart'])){
                if(
    product_exists($pid)) return;
                
    $max=count($_SESSION['cart']);
                
    $_SESSION['cart'][$max]['productid']=$pid;
                
    $_SESSION['cart'][$max]['qty']=$q;
            }
            else{
                
    $_SESSION['cart']=array();
                
    $_SESSION['cart'][0]['productid']=$pid;
                
    $_SESSION['cart'][0]['qty']=$q;
            }
        }
        function 
    product_exists($pid){
            
    $pid=intval($pid);
            
    $max=count($_SESSION['cart']);
            
    $flag=0;
            for(
    $i=0;$i<$max;$i++){
                if(
    $pid==$_SESSION['cart'][$i]['productid']){
                    
    $flag=1;
                    break;
                }
            }
            return 
    $flag;
        }

    ?>

    I REALY need this so if there is enyone that can help me that will be nice , i hope there is someone that understand what i wanted to say , sorry for my bad ENG

  2. #2
    Join Date
    Jun 2009
    Posts
    18
    Maybe they deleted because it is not in php forum but js.

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,360
    I seem to recall you were given an answer and asking a PHP question in a JavaScript forum is not helping either.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  4. #4
    Join Date
    Jun 2009
    Posts
    18
    Also it is a very poor coding. I am not so good with php but most of the languages supports "maximum" property for NumericUpAndDown control.
    You may write something like:
    Code:
    myNUD.maximum = SQLQuery'SELECT Qty FROM TableProducts
    WHERE pid = ProductID'
    while initializing the page. So once the page loaded the client can not input a number more than your stock.

    And you may add the same quantity info in a div somewhere in your page. So you will let each client to see how much left of that product in the stock somewhere on the page.

    Maybe you may add the same validation check upon submit button. Because, it is possible that another client bought some of that product in the meanwhile.
    Example:
    Code:
    some button submit function ()
    NewQuery= SQLQuery'SELECT Qty FROM TableProducts
    WHERE pid = ProductID';
    if (myNUD.value <= NewQuery) {validate submit} else {alert('There is only '+NewQuery+' left in the stocks')};
    PS: My coding syntax is useless. I don't know how to use the right syntax for php. None of the programming languages will recognize the syntax I wrote above. It is only for logical purposes!
    Last edited by Flashbond; 02-03-2014 at 10:08 AM.

  5. #5
    Join Date
    Feb 2014
    Posts
    11
    Quote Originally Posted by Flashbond View Post
    Also it is a very poor coding. I am not so good with php but most of the languages supports "maximum" property for NumericUpAndDown control.
    You may write something like:
    Code:
    myNUD.maximum = SQLQuery'SELECT Qty FROM TableProducts
    WHERE pid = ProductID'
    while initializing the page. So once the page loaded the client can not input a number more than your stock.

    And you may add the same quantity info in a div somewhere in your page. So you will let each client to see how much left of that product in the stock somewhere on the page.

    Maybe you may add the same validation check upon submit button. Because, it is possible that another client bought some of that product in the meanwhile.
    Example:
    Code:
    some button submit function ()
    NewQuery= SQLQuery'SELECT Qty FROM TableProducts
    WHERE pid = ProductID';
    if (myNUD.value <= NewQuery) {validate submit} else {alert('There is only '+NewQuery+' left in the stocks')};
    PS: My coding syntax is useless. I don't know how to use the right syntax for php. None of the programming languages will recognize the syntax I wrote above. It is only for logical purposes!

    htx man for replay , well i made this with tutorials over intrnet and everything works just fine just this ! i understand you what you mean in that logical i know what need to be done ... but dont know the code for it ... how to inplement that solution in my script . where and what to change

  6. #6
    Join Date
    Jun 2009
    Posts
    18
    OK, make some reading and come back.
    http://www.kethinov.com/jsstepper.php

  7. #7
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,360
    Can you take this to the SQL forums please, it is not javascript.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles