473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.
Jun 27 '07 #1
4 3645
ronnil
134 Expert 100+
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 Expert 4TB
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
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 Expert 1GB
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
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...
2
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...
5
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"?...
9
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...
4
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
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...
10
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...
14
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...
8
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...

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.