473,799 Members | 3,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to match user selected item with their respective quantity and size

88 New Member
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:
Expand|Select|Wrap|Line Numbers
  1.  <script language="JavaScript">
  2.  
  3. <!--
  4.  
  5. function validate_form ( )
  6. {
  7.     valid = true;
  8. alert (document.Lform.quantity.selectedIndex);
  9.     if ( document.Lform.quantity.selectedIndex == 0 )
  10.         {
  11.                 alert ( "Please select your quantity!" );
  12.                 Lform.quantity.focus();
  13.                 valid = false;
  14.         }
  15.     else if ( document.Lform.size.selectedIndex == 0 )
  16.         {
  17.                 alert ( "Please select your size!" );
  18.                 Lform.size.focus();
  19.                 valid = false;
  20.         }
  21.             return valid;
  22. }
  23. //-->
  24. </script>
However, i don;t know how to correspond respective product with their respective choosen quantity and size.

the following is my current coding,
Expand|Select|Wrap|Line Numbers
  1.  <?php
  2.  foreach ($_POST as $key => $value) {
  3.     echo "key: ".$key.", value: ".$value."<br>";
  4.         $sql = "INSERT INTO orders (imageid, userid, time) VALUES ('$key', '$userid', '$date')";
  5.         mysql_query($sql); 
  6.     }
  7.  
  8. echo "Please select your size and quantity for purchase:";
  9.     echo "<table border = '1'>";
  10.                 echo "<tr>";
  11.                 echo "<td>Title";
  12.                 echo "<td>Brand";
  13.                 echo "<td>Price";
  14.                 echo "<td>Size";
  15.                 echo "<td>Quantity";
  16.                 echo "</tr>";
  17. $sql2="SELECT imageid FROM orders";
  18. $result=mysql_query($sql2);
  19. while($row = mysql_fetch_array($result)) {
  20.                 echo "<br>";
  21.                 $sql3="SELECT brand, price, title FROM ladies WHERE id=".$row['imageid'];
  22.                 $ImageResult = mysql_query($sql3);
  23.                 $ImageDetail = mysql_fetch_array($ImageResult);
  24.                 echo "<tr>";
  25.                 echo "<td>".$ImageDetail['title']."";
  26.                 echo "<td>".$ImageDetail['brand']."";
  27.                 echo "<td>".$ImageDetail['price']."";
  28.                 echo"<td>";
  29.  
  30.                 echo"
  31.             <select id='size' name='size' tabindex='11'>
  32.                             <option value='0'>---
  33.                             <option value='1' >S
  34.                             <option value='2'>M
  35.                             <option value='3'>L
  36.                             <option value='4'>XL
  37.                     </select>
  38.                     </td>";     
  39.     //echo"    ";    
  40.  
  41.  
  42.     echo"
  43.         <td>
  44.             <select id='NO' name='quantity' tabindex='11'>
  45.                             <option value='0'>---
  46.                             <option value='1' >1
  47.                             <option value='2'>2
  48.                             <option value='3'>3
  49.                             <option value='4'>4
  50.                             <option value='5'>5
  51.                             <option value='6'>6
  52.                             <option value='7'>7
  53.                             <option value='8'>8
  54.                             <option value='9'>9
  55.                             <option value='10'>10
  56.                     </select>
  57.                     </td>"; 
  58.                  echo "</tr>";            
  59.                 }
  60.             echo "</table>";
  61.     echo "<input type = 'submit' value = 'order'>";
  62. ?>
anyone can help me with this, thank you very much. it is bit urgent as the project deadline is near.



Please enclose your coding with [code] tags
[Please Find how!]
Jul 7 '07
14 2098
ak1dnar
1,584 Recognized Expert Top Contributor
the default is all 1, but my supervisor don;t think it is practical in real life to let everyone just buy one and they should be able to select the size they wear. that is why i have to do the validation of size and quantity for each item they buy.

i have to insert their size and quantity for the respective item in database, so i have to know which size and quantity is belong to which item.

sure, i will wait for your kind reply. thanks. :)
Just Listen to me again,

Why Customer(s) comes to e-commerce sites. to Buy isn't it.
Do they ever purchasing "0" items. NO.
Its should be greater than 1 always.
Then Size, As I know you are going to display S,M,L,XL with your products.
So can't we set one of them by default. If User don't want that Size say XL is set by default and he needs L so he will do it.

However get in touch with your SUPERvisor :)

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con = mysql_connect('localhost', 'root', 'dba') or die ("Could not connect to the Database");
  3. mysql_select_db('test', $con) or die (mysql_error()); 
  4. $query1 = 'Select p_id from products';
  5. $result1 = mysql_query($query1);
  6. $query2 = 'Select p_id from products';
  7. $result2 = mysql_query($query2);
  8. ?>
  9. <html>
  10. <head>
  11. <script language="JavaScript" type="text/javascript">
  12. function menuChk(){
  13. <?php
  14. while ($row1 = mysql_fetch_array($result1))
  15. {
  16. ?>
  17. var Str<?=$row1['p_id']?> = document.formObj.Qty<?=$row1['p_id']?>.selectedIndex;
  18. if (Str<?=$row1['p_id']?> == 0){
  19. alert("Please select the Quantity!");
  20. document.formObj.Qty<?=$row1['p_id']?>.focus();
  21. return false;
  22. }
  23. <?
  24. }
  25. ?>
  26. }
  27. </script>
  28. </head>
  29. <body>
  30. <form id="formObj" name="formObj" method="post" action="server.php" onsubmit="return menuChk();">
  31. <?php
  32. while ($row2 = mysql_fetch_array($result2))
  33. {
  34. ?>
  35. <select name="Qty<?=$row2['p_id']?>">
  36. <option value="0">0</option>
  37. <option value="1">1</option>
  38. <option value="2">2</option>
  39. </select>
  40. <br />
  41. <?php
  42. }
  43. ?>
  44. <input name="" type="submit" />
  45. </form>
  46. </body>
  47. </html>
  48.  
  49.  
This will print somting like this dynamically.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language="JavaScript" type="text/javascript">
  4. function menuChk(){
  5. var Str143 = document.formObj.Qty143.selectedIndex;
  6. if (Str143 == 0){
  7. alert("Please select the Quantity!");
  8. document.formObj.Qty143.focus();
  9. return false;
  10. }
  11. var Str144 = document.formObj.Qty144.selectedIndex;
  12. if (Str144 == 0){
  13. alert("Please select the Quantity!");
  14. document.formObj.Qty144.focus();
  15. return false;
  16. }
  17. var Str145 = document.formObj.Qty145.selectedIndex;
  18. if (Str145 == 0){
  19. alert("Please select the Quantity!");
  20. document.formObj.Qty145.focus();
  21. return false;
  22. }
  23. var Str146 = document.formObj.Qty146.selectedIndex;
  24. if (Str146 == 0){
  25. alert("Please select the Quantity!");
  26. document.formObj.Qty146.focus();
  27. return false;
  28. }
  29. var Str147 = document.formObj.Qty147.selectedIndex;
  30. if (Str147 == 0){
  31. alert("Please select the Quantity!");
  32. document.formObj.Qty147.focus();
  33. return false;
  34. }
  35. var Str148 = document.formObj.Qty148.selectedIndex;
  36. if (Str148 == 0){
  37. alert("Please select the Quantity!");
  38. document.formObj.Qty148.focus();
  39. return false;
  40. }
  41. }
  42. </script>
  43. </head>
  44. <body>
  45. <form id="formObj" name="formObj" method="post" action="server.php" onsubmit="return menuChk();">
  46. <select name="Qty143">
  47. <option value="0">0</option>
  48. <option value="1">1</option>
  49. <option value="2">2</option>
  50. </select>
  51. <br />
  52. <select name="Qty144">
  53. <option value="0">0</option>
  54. <option value="1">1</option>
  55. <option value="2">2</option>
  56. </select>
  57. <br />
  58. <select name="Qty145">
  59. <option value="0">0</option>
  60. <option value="1">1</option>
  61. <option value="2">2</option>
  62. </select>
  63. <br />
  64. <select name="Qty146">
  65. <option value="0">0</option>
  66. <option value="1">1</option>
  67. <option value="2">2</option>
  68. </select>
  69. <br />
  70. <select name="Qty147">
  71. <option value="0">0</option>
  72. <option value="1">1</option>
  73. <option value="2">2</option>
  74. </select>
  75. <br />
  76. <select name="Qty148">
  77. <option value="0">0</option>
  78. <option value="1">1</option>
  79. <option value="2">2</option>
  80. </select>
  81. <br />
  82. <input name="" type="submit" />
  83. </form>
  84. </body>
  85. </html>
  86.  
  87.  
Jul 11 '07 #11
kang jia
88 New Member
i do think what you said previously is very true , we can just set default value ma, later user want to change, they will change, i will validate my reasons with my supervisor, thanks for your kind help . but if i choose to use the defult one, how should i insert in database.

Remaining section removed from the post,Please read the next thread to find out the reason.
Jul 14 '07 #12
ak1dnar
1,584 Recognized Expert Top Contributor
Sorry I have to delete this post from the thread.

Reason:
Cannot see the post. its empty.
May be its too long.

Please Remove the unwanted static contents from your coding and re-post it.

Thanks!
-Ajaxrand
Jul 16 '07 #13
kang jia
88 New Member
Sorry I have to delete this post from the thread.

Reason:
Cannot see the post. its empty.
May be its too long.

Please Remove the unwanted static contents from your coding and re-post it.

Thanks!
-Ajaxrand

thanks for your kind help, i just sovled it with my other friends' help, really thanks, you are so nice and kind to help me!
Jul 17 '07 #14
ak1dnar
1,584 Recognized Expert Top Contributor
thanks for your kind help, i just sovled it with my other friends' help, really thanks, you are so nice and kind to help me!
Glad to hear that !Well done!
Come back any time to TSDN.
-Ajaxrand
Jul 17 '07 #15

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

Similar topics

14
5259
by: Sonic | last post by:
I have an MDE file that is growing exponentially (from 3,900 KB to over 132,000 KB today). I am not saving data in this MDE, although I use a mix of offline and SQL tables for Read Only querying. I also have many forms and some reports and queries. Many people use this DB on a daily basis and there is constantly someone in it, virtually every minute. The DB tends to crash every couple of weeks. I am wondering if the size of this...
0
2420
by: Norbert Heidbüchel | last post by:
Hi all, I have read a lot of postings and web pages about drag and drop and treeviews, but could not find an answer to my problem. Sorry, if I missed something. I am trying to drag and drop treenodes defined by myself and don't understand, how to get the nodes data in the dragdrop event. I'm not very experienced in .NET and for sure there is a simple solution. I've written a short sample program, based on well known examples,
5
2344
by: Stephen | last post by:
Could someone please help me with some validation. I have to write code which checks to see whether a dropdown list is populated with a value or a checkbox is checked. I want the code to run on the on-click of a button. My page has 1 dropdown list and two checkboxes. So I either want the user to choose an item from the dropdownlist OR tick a checkbox(it doesn't matter if they tick both checkboxes). I can't allow the user to fill in the...
4
2463
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item, what do I need to do in order to return the "option value" of the control? Moe !--- returned value of the control
9
2905
by: Jimbo | last post by:
Hello, I have a user request to build a form in an Access database where the user can check off specific fields to pull in a query. For example, let's say I have 10 fields in a table. The user wants to be able to check off anywhere between 1 and all 10 fields in a form and have it return a select query with just the fields that were checked off. There are multiple users, so not all users will be checking off the same fields. Some...
0
4102
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL, TYPE VARCHAR(30) NOT NULL, DURATION TIME , YEAR_RELEASE YEAR NOT NULL, DESCRIPTION TEXT,
1
1448
by: goutam12345 | last post by:
Hello experts, Please help.... My checkboxes are not passing respective textboxes values to another page My checkboxes are moving in a loop <input type="checkbox" name="chkID" id="chkID" value="<?=$rowSubjectsx?>"> My text boxes are also moving in a loop <input type="text" name="quantity" id="quan" size="3"/> I want to show respective check boxes subjects and quantity to another page Please help.......
5
2692
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hallo, I have a radiobuttonlist control that is added on a custom Web User Control. This control has a property that exposes the SelectedIndex property of the embedded radiobuttonlist. When running this in IE, behaviour is as I would expect it. If I select an item and do a postback, the page remembers my selection when reloading, and the SelectedIndex property of my control returns the correct value.
2
3689
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a different item no in it..then, these records will be saved in a temporary datatable (which i made in a separate class, the name is WBASKET)...The item nos of these records will be displayed in a combobox, say item1, item2, etc.. then,i have a datagrid...
0
9687
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
9541
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
10482
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...
0
10251
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10225
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
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7564
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
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2938
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.