how to add in quantity and size in my online shopping

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kang jia
    New Member
    • Jun 2007
    • 88

    how to add in quantity and size in my online shopping

    hi

    i am doing online shop now using php, my product is clothes, Now i am able to let users to order, however i don;t know how should i validate quantity and size field when they select that specific clothes. i just pass it to do_addcart.php but it seems the value never pass through. what should i do now?

    how can i let users to put in quantity and size field when they select clothes? i have to validate the quantity and size field before add into cart. also i have to know the vaule of their input.
  • ronnil
    Recognized Expert New Member
    • Jun 2007
    • 134

    #2
    a posibility is to make a hidden field where you store the quantity value. make a div tag where you display that value, and then two image buttons (+ and -) when the user clicks one of these buttons you increase/decrease the number.

    [CODE=javascript]<script language="javas cript">
    function changeQuant(qua ntity)
    {
    var hiddenObj = document.getEle mentById('quant ity');
    var currentQuant = hiddenObj.value ;
    currentQuant = currentQuant + quantity;

    hiddenObj.value = currentQuant;
    document.getEle mentById('show_ quant').innerHT ML = currentQuant;
    }

    </script>
    <form>
    <input type="hidden" name="quantity" id="quantity" value="1" /> <!-- the default value is ofc 1 item -->
    </form>

    <div id="show_quant" ><img onclick="change Quant(-1)" alt="-" /><img onclick="change Quant(1)" alt="+" />[/CODE]

    ofcourse the hidden field must be attached to whatever form you use to make the order. when submitting it, you will then have a variable by the name of quantity.

    This is just one of many solutions :)

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      Could you show us the code you are using? It helps to see the code your trying to debug :)

      My solution to a similar functionality was to add a text field to my form and allow the user to type the quantity they wanted. Then that field would simply be passed to the next page using HTTP_POST and I would validate it there.

      If you are not sure how that works you can check out this article , where it is discussed in detail.

      Comment

      • kang jia
        New Member
        • Jun 2007
        • 88

        #4
        yes, i have do the same as what u said, i validate it in the next page, the code is like the following:
        in the first page:
        [code=php]
        $getName = $_GET['name'];

        if (isset($getName )){
        $selPaint = "SELECT * from ladies where brand ='".$getName."' ";

        }
        else{
        $selPaint = "SELECT * from ladies";
        }

        $execPaint = mysql_query($se lPaint);
        while($thisArt = mysql_fetch_arr ay($execPaint)) {

        $fName = $thisArt['filename'];
        $id = $thisArt['id'];
        $_SESSION['id']=$id;

        //echo "<input type='hidden' name='vin' value=$id>";

        echo"<table bgcolor='#FFFFF F' border='1' width='570' height='200' cellspacing='5' >";
        $title=$thisArt['title'];
        echo "<h3><td>".$tit le."</h3>";

        $text=wordwrap( $title,2,"<br />\n");

        echo "<a href =".$uploaddir.$ fName.">";
        echo "<img src=".$thumbdir ."thumb_".$fNam e."></a><br>";

        $price=$thisArt['price'];
        echo "<td><br><br><b r>";
        $Des = "<h4>".$thi sArt['description']."</h4><br>";
        $text1=wordwrap ($Des,60,"<br />\n");
        echo"<h3>".$tex t1."</h3></td><br>";
        /*if($role =="admin"){
        echo "<td><a href=\"do_delet e.php?id=".$id. "\">Delete</a></td>";
        echo "<td><a href=\"updateco ntact.php?id=". $id."\">Update</a></td>";

        }*/
        echo"</table>";
        echo "<BR>";

        if (isset($_SESSIO N['userid'])) {

        if($role =="admin"){
        //echo"&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;";
        echo "<a href=\"do_delet e.php?id=".$id. "\">Delete</a>";
        echo "&nbsp;&nbs p;";
        echo "<a href=\"updateco ntact.php?id=". $id."\">Update</a>";
        echo "<br>";
        echo "<br>";
        }
        $rprice=round($ price,2);
        if(isset($curre ncy)){
        $asd = $price*$cal;
        $round=round($a sd,2);
        echo"<table>";
        echo"<tr>";
        echo"<td>";
        echo "<input type = 'checkbox' value = '1' name = '".$id."'>Bu y this poster. Currency: ".$look.". Price = $". $round;
        echo"</tr>";
        echo "</table>";
        echo"
        <tr>
        <td class='FormLabe l'><font color='red'>*</font> <span class='error'>< nobr>Size:</nobr></span>
        </td>
        <td class='formFiel dSmall'>
        <select id='size' name='size' tabindex='11'>
        <option value='0'>---</option>
        <option value='1' >S</option>
        <option value='2'>M</option>
        <option value='3'>L</option>
        <option value='4'>XL</option>
        </select>
        </td>
        </tr>";
        echo"&nbsp;&nbs p;&nbsp;&nbsp;" ;
        echo"
        <tr>
        <td class='loginFor mLabel'><font color='red'>*</font> <span class='error'>< nobr>Quantity:</nobr></span>
        </td>
        <td class='formFiel dSmall'>
        <select id='NO' name='quantity' tabindex='11'>
        <option value='0'>---</option>
        <option value='1' >1</option>
        <option value='2'>2</option>
        <option value='3'>3</option>
        <option value='4'>4</option>
        <option value='5'>5</option>
        <option value='6'>6</option>
        <option value='7'>7</option>
        <option value='8'>8</option>
        <option value='9'>9</option>
        <option value='10'>10</option>
        </select>
        </td>
        </tr>";

        }
        else{
        echo "<input type = 'checkbox' value = '1' name = '".$id."'>Bu y this poster. Price = $ S.G ".$rprice;

        echo" &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;";
        echo"
        <tr>
        <td class='FormLabe l'><font color='red'>*</font> <span class='error'>< nobr>Size:</nobr></span>
        </td>
        <td class='formFiel dSmall'>
        <select id='size' name='size' tabindex='11'>
        <option value='0'>---</option>
        <option value='1' >S</option>
        <option value='2'>M</option>
        <option value='3'>L</option>
        <option value='4'>XL</option>
        </select>
        </td>
        </tr>";
        echo"&nbsp;&nbs p;&nbsp;&nbsp;" ;
        echo"<tr>
        <td class='loginFor mLabel'><font color='red'>*</font> <span class='error'>< nobr>Quantity:</nobr></span>
        </td>
        <td class='formFiel dSmall'>
        <select id='NO' name='quantity' tabindex='11'>
        <option value='0'>---</option>
        <option value='1' >1</option>
        <option value='2'>2</option>
        <option value='3'>3</option>
        <option value='4'>4</option>
        <option value='5'>5</option>
        <option value='6'>6</option>
        <option value='7'>7</option>
        <option value='8'>8</option>
        <option value='9'>9</option>
        <option value='10'>10</option>
        </select>
        </td>
        </tr>";
        echo "<br>";

        }

        }

        }
        [/code]
        in next page:

        [code=php]
        $userid = $_SESSION['userid'];

        $date=date("D j-M-Y G:i:s");

        echo "Image ID = ".$_SESSION['id']."<br>";
        //echo "Image ID = ".$_POST['vin1']."<br>";
        //echo "Image ID = ".$_POST['vin2']."<br>";
        //echo "Image ID = ".$_POST['vin3']."<br>";

        $chkbox2 = $_POST['quantity'];
        $chkbox3 = $_POST['size'];
        echo $chkbox2;
        echo $chkbox3;

        if ($chkbox2 == 0 || $chkbox3 == 0){
        echo "<script>alert( 'you did not select your quantity and size, we will direct you back')</script>";
        //header('Refresh : 3; url=index1.php' );
        //break;
        echo "<meta http-equiv='refresh' content='1;url= index1.php'>";
        }

        else {
        foreach ($_POST as $key => $value) {
        echo "key: ".$key.", value: ".$value."<br>" ;
        $sql = "INSERT INTO orders (imageid, userid, time, quantity, size) VALUES ('$key', '$userid', '$date','$chkbo x2','$chkbox3') ";
        mysql_query($sq l);
        }

        //header('Refresh : 3; url=cart.php');
        echo "<meta http-equiv='refresh' content='5;url= http://google.com'>";
        echo"<BR>";
        echo "Your order is being processed, you will be directed to your shopping cart soon";
        }
        [/code]

        this is code i have done, but it did not post value to the next page, it always 0, and image id is always 16, how should i solve this? thanks for your kind help :)
        Last edited by Atli; Jun 30 '07, 03:41 PM. Reason: Added code tags and edited to fix a bug (apparently)

        Comment

        • kovik
          Recognized Expert Top Contributor
          • Jun 2007
          • 1044

          #5
          You input this into your database very strangely. On the second page, call a print_r($_POST) and tell us what you get.

          Comment

          Working...