473,666 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to add in quantity and size in my online shopping

88 New Member
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.
Jun 27 '07 #1
4 3688
ronnil
134 Recognized Expert New Member
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.

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function changeQuant(quantity)
  3. {
  4.     var hiddenObj = document.getElementById('quantity');
  5.     var currentQuant = hiddenObj.value;
  6.     currentQuant = currentQuant + quantity;
  7.  
  8.     hiddenObj.value = currentQuant;
  9.     document.getElementById('show_quant').innerHTML = currentQuant;
  10. }
  11.  
  12. </script>
  13. <form>
  14. <input type="hidden" name="quantity" id="quantity" value="1" /> <!-- the default value is ofc 1 item -->
  15. </form>
  16.  
  17. <div id="show_quant"><img onclick="changeQuant(-1)" alt="-" /><img onclick="changeQuant(1)" alt="+" />
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 :)
Jun 27 '07 #2
Atli
5,058 Recognized Expert Expert
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.
Jun 27 '07 #3
kang jia
88 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. $getName = $_GET['name'];
  2.  
  3.     if (isset($getName)){
  4.         $selPaint = "SELECT * from ladies where brand ='".$getName."'";
  5.  
  6.     }
  7.     else{
  8.         $selPaint = "SELECT * from ladies";
  9.     }
  10.  
  11. $execPaint = mysql_query($selPaint);
  12.     while($thisArt = mysql_fetch_array($execPaint)){
  13.  
  14.         $fName = $thisArt['filename'];
  15.         $id = $thisArt['id'];
  16.         $_SESSION['id']=$id;
  17.  
  18.      //echo "<input type='hidden' name='vin' value=$id>";
  19.  
  20.         echo"<table bgcolor='#FFFFFF' border='1' width='570' height='200' cellspacing='5'>";
  21.         $title=$thisArt['title'];
  22.      echo "<h3><td>".$title."</h3>";     
  23.  
  24.     $text=wordwrap($title,2,"<br />\n");
  25.  
  26.     echo "<a href =".$uploaddir.$fName.">";
  27.         echo "<img src=".$thumbdir."thumb_".$fName."></a><br>";
  28.  
  29.         $price=$thisArt['price'];
  30.      echo "<td><br><br><br>";    
  31.         $Des = "<h4>".$thisArt['description']."</h4><br>";
  32.         $text1=wordwrap($Des,60,"<br />\n");
  33.         echo"<h3>".$text1."</h3></td><br>";
  34.         /*if($role =="admin"){
  35.         echo "<td><a href=\"do_delete.php?id=".$id."\">Delete</a></td>";
  36.         echo "<td><a href=\"updatecontact.php?id=".$id."\">Update</a></td>";
  37.  
  38.         }*/
  39.     echo"</table>";
  40.         echo "<BR>";
  41.  
  42.         if (isset($_SESSION['userid'])) {
  43.  
  44.         if($role =="admin"){
  45.         //echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  46.         echo "<a href=\"do_delete.php?id=".$id."\">Delete</a>";
  47.         echo "&nbsp;&nbsp;";
  48.         echo "<a href=\"updatecontact.php?id=".$id."\">Update</a>";
  49.         echo "<br>";
  50.         echo "<br>";
  51.         }
  52.         $rprice=round($price,2);
  53.         if(isset($currency)){
  54.         $asd = $price*$cal;
  55.         $round=round($asd,2);
  56.        echo"<table>";
  57.        echo"<tr>";
  58.        echo"<td>";
  59.         echo "<input type = 'checkbox' value = '1' name = '".$id."'>Buy this poster. Currency: ".$look.". Price = $". $round;
  60.       echo"</tr>";
  61.     echo "</table>";
  62.         echo"
  63.             <tr>
  64.                 <td class='FormLabel'><font color='red'>*</font>    <span class='error'><nobr>Size:</nobr></span>
  65. </td>
  66.                 <td class='formFieldSmall'>
  67.             <select id='size' name='size' tabindex='11'>
  68.                             <option value='0'>---</option>
  69.                             <option value='1' >S</option>
  70.                             <option value='2'>M</option>
  71.                             <option value='3'>L</option>
  72.                             <option value='4'>XL</option>
  73.                     </select>
  74.                     </td>
  75.                     </tr>";     
  76.     echo"&nbsp;&nbsp;&nbsp;&nbsp;";    
  77.     echo"
  78.             <tr>
  79.                 <td class='loginFormLabel'><font color='red'>*</font>    <span class='error'><nobr>Quantity:</nobr></span>
  80. </td>
  81.                 <td class='formFieldSmall'>
  82.             <select id='NO' name='quantity' tabindex='11'>
  83.                             <option value='0'>---</option>
  84.                             <option value='1' >1</option>
  85.                             <option value='2'>2</option>
  86.                             <option value='3'>3</option>
  87.                             <option value='4'>4</option>
  88.                             <option value='5'>5</option>
  89.                             <option value='6'>6</option>
  90.                             <option value='7'>7</option>
  91.                             <option value='8'>8</option>
  92.                             <option value='9'>9</option>
  93.                             <option value='10'>10</option>
  94.                     </select>
  95.                     </td>
  96.                     </tr>";     
  97.  
  98.     }
  99.         else{
  100.     echo "<input type = 'checkbox' value = '1' name = '".$id."'>Buy this poster. Price = $ S.G ".$rprice;
  101.  
  102.     echo"    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  103.     echo"
  104.             <tr>
  105.                 <td class='FormLabel'><font color='red'>*</font>    <span class='error'><nobr>Size:</nobr></span>
  106. </td>
  107.                 <td class='formFieldSmall'>
  108.             <select id='size' name='size' tabindex='11'>
  109.                             <option value='0'>---</option>
  110.                             <option value='1' >S</option>
  111.                             <option value='2'>M</option>
  112.                             <option value='3'>L</option>
  113.                             <option value='4'>XL</option>
  114.                     </select>
  115.                     </td>
  116.                     </tr>"; 
  117. echo"&nbsp;&nbsp;&nbsp;&nbsp;";                    
  118.             echo"<tr>
  119.                 <td class='loginFormLabel'><font color='red'>*</font>    <span class='error'><nobr>Quantity:</nobr></span>
  120. </td>
  121.                 <td class='formFieldSmall'>
  122.             <select id='NO' name='quantity' tabindex='11'>
  123.                             <option value='0'>---</option>
  124.                             <option value='1' >1</option>
  125.                             <option value='2'>2</option>
  126.                             <option value='3'>3</option>
  127.                             <option value='4'>4</option>
  128.                             <option value='5'>5</option>
  129.                             <option value='6'>6</option>
  130.                             <option value='7'>7</option>
  131.                             <option value='8'>8</option>
  132.                             <option value='9'>9</option>
  133.                             <option value='10'>10</option>
  134.                     </select>
  135.                     </td>
  136.                     </tr>";
  137.             echo "<br>";
  138.  
  139.             }
  140.  
  141.         }
  142.  
  143.     }
  144.  
in next page:

Expand|Select|Wrap|Line Numbers
  1. $userid = $_SESSION['userid'];
  2.  
  3.     $date=date("D j-M-Y G:i:s");
  4.  
  5.         echo "Image ID = ".$_SESSION['id']."<br>";
  6.         //echo "Image ID = ".$_POST['vin1']."<br>";
  7.         //echo "Image ID = ".$_POST['vin2']."<br>";
  8.         //echo "Image ID = ".$_POST['vin3']."<br>";
  9.  
  10.         $chkbox2 = $_POST['quantity'];
  11.         $chkbox3 = $_POST['size'];
  12.         echo $chkbox2;
  13.         echo $chkbox3;
  14.  
  15.         if ($chkbox2 == 0 || $chkbox3 == 0){
  16.                 echo "<script>alert('you did not select your quantity and size, we will direct you back')</script>";
  17.                 //header('Refresh: 3; url=index1.php');
  18.                 //break;
  19.                 echo "<meta http-equiv='refresh' content='1;url=index1.php'>";
  20.         }
  21.  
  22.         else {
  23.             foreach ($_POST as $key => $value) {
  24.     echo "key: ".$key.", value: ".$value."<br>";
  25.         $sql = "INSERT INTO orders (imageid, userid, time, quantity, size) VALUES ('$key', '$userid', '$date','$chkbox2','$chkbox3')";
  26.         mysql_query($sql); 
  27.     }
  28.  
  29.     //header('Refresh: 3; url=cart.php');
  30.     echo "<meta http-equiv='refresh' content='5;url=http://google.com'>";
  31.     echo"<BR>";
  32.     echo "Your order is being processed, you will be directed to your shopping cart soon";
  33.         }
  34.  
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 :)
Jun 30 '07 #4
kovik
1,044 Recognized Expert Top Contributor
You input this into your database very strangely. On the second page, call a print_r($_POST) and tell us what you get.
Jun 30 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2474
by: Michael J. Astrauskas | last post by:
I'm developing a fairly basic shopping cart. My original implementation had the user click on a link to add an item to the cart (addtocart.php?item=123456). I figured it could just increase the quantity every time the user clicked. However, with caching turned off the quantity is increased if the user presses back and then forward in his/her browser. Is there any simple way to avoid this? I noticed that a lot of online retailers don't...
2
1618
by: Gary Vidal | last post by:
I have a shopping cart webpage that shows a product and the Quantity they would like to order: When you click the link I want to take the quantity that they entered in the textbox and post that to the next page. But it keeps the original quantity I added to the viewstate. Where can i code this to post the correct quantity. Here is the code-behind I use. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)...
5
2558
by: HandersonVA | last post by:
should I set to "0" as a default value on a quantity and a price field or set to "null"? if a user enter nothing on the quantity or price field on a web browser, should I treat it as null or "0"? I am so confused about this concept. please advise me. thank you.
9
2584
by: Rob Meade | last post by:
Hi all, Ok - so I've got the array thing going on, and the session thing going on, and up until now its all been ok. I've got my view basket page which is displaying 3 rows (as an example) - I have an input box on each row enabling the user to update the quantity. If the enter a zero I need to remove the item from the array....
4
7462
by: Jigar A. Thakor | last post by:
how to create online shopping website.. ?? any architecture ?? How to design any guidlines ? and what is verisign ?? other secure protection needed ?? i want to develop in C#,Asp.net,Sql Server...
8
36264
by: jimmyg123 | last post by:
Hi, I'm trying to do something similar. This is my javascript <script type='text/javascript'> function totalise(price,total) { var qty = window.document.getElementById('qty').value; var result = total; result.value = price * qty; }
10
1920
by: vectorBS | last post by:
Hi, I need a suggestion as to which method will be most efficient way of accomplishing this task. I need to build invoice report with Garment Sizes and Quantity. There are seperate records for different sizes with their corresponding quantity in the shipment table. I have to display this information in Invoice Report in a single row with quntities under size lables ( S, M, L, XL, XXL ). Access doesnt allow grouping on multiple fields so i...
14
2084
by: kang jia | last post by:
hi i am doing shopping online, i will let user choose their prodcut in the first page and then when they click" order" button, they will be redirected to do_addcart.php. i will insert their orders into "orders" table and retrieve them back and ask user to select their respective quantity and size. i have used Javascript validation: the code is below: <script language="JavaScript"> <!-- function validate_form ( ) {
8
1883
by: Just Me | last post by:
Hi, OK, Ive been asked to provide a public site with a means of selling some products, I have never done this before, so im a bit of a newbie really. What I am looking for is a method of acheiving this within the ASP.NET develpment arena, Byt which I dont mean that I want to design a shopping cart system, I want a low impact , low cost if possible way of being able to set up my products and sell them using a third party like worldpay...
0
8454
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8362
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8878
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8560
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7389
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6200
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5671
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.