473,786 Members | 2,462 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 #1
14 2095
ak1dnar
1,584 Recognized Expert Top Contributor
Moving Thread from PHP Articles....

Post your question in a relevant forum
Make sure you are not posting in an Articles section
Jul 7 '07 #2
ak1dnar
1,584 Recognized Expert Top Contributor
I can't imagine the way you have used to enter the records from your first page to this php Hope its working fine.

This is not the correct way to do the thing.First Let me know, is there any Relation ship between ORDERS table and LADIES (Strange ha :) )Table.
Jul 7 '07 #3
kang jia
88 New Member
I can't imagine the way you have used to enter the records from your first page to this php Hope its working fine.

This is not the correct way to do the thing.First Let me know, is there any Relation ship between ORDERS table and LADIES (Strange ha :) )Table.


hi

Orders and Ladies table is interrelated, i will insert whatever users purchases into orders table and there is imageid ( which is foreign key to Ladies table) and userid, so i will know which user choosed which item from imageid. then i use this imageid to retrieve back the value in ladies table.

the code in the first page is like this

Expand|Select|Wrap|Line Numbers
  1. :
  2.  
  3. <?ob_start();
  4.     session_start(); ?>
  5. <html>
  6. <head>
  7. <link rel="stylesheet" type="text/css" href="shop.css" /><div id="h">Ladies' Apparels</div>
  8.  
  9. </head>
  10. <body>
  11. <div id="leftcol" >
  12.  
  13.     <?php
  14. //session_start() does not create new session, but identifies same session from do_login.php
  15. require("db.php");
  16. require("currency.php");
  17.  
  18. $cur = new currency();
  19. $arr = $cur->get_all_currencies();
  20. $currency=$_POST['currency'];
  21. $_SESSION['currency']=$currency;
  22. mysql_connect(MACHINE, USER, '');
  23. mysql_select_db(DBNAME);
  24.  
  25. // PLEASE CHANGE ACCORDINGLY
  26. $uploaddir = "images/"; //folder to upload actual images
  27. $thumbdir = "thumbnails/"; //folder to upload thumbnails
  28.  
  29. //Obtaining session variables (From do_login.php)
  30. $uname = $_SESSION['username'];
  31. $pwd =$_SESSION['passw'];
  32. $role = $_SESSION['role']; 
  33. $userid=$_SESSION['userid'];
  34.  
  35. if (isset($_SESSION['username'])) {
  36.         echo "<b>Welcome ". $uname."</b><br>Your <a href = 'cart.php'>Shopping Cart</a>"; //print welcome mesage
  37.     }
  38.  
  39.     $sel = "select distinct brand from ladies order by title asc";
  40.     $res = mysql_query($sel);
  41.     echo"<table border='1' cellspacing='10' width='50' height='900' align='left'><td>";
  42.  
  43.     echo"<img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/field.jpg' width='150' height='80' align='center'><br>";
  44.     echo "<ul>";
  45.     echo "<br><li><h4><a href=index1.php>All brands</a></h4></li><br>";
  46.     while($rec = mysql_fetch_array($res)){
  47.         $name = $rec['brand'];
  48.         echo "<h4><a href = index1.php?name=".$name.">".$name."</a></h4>";
  49.     }
  50. echo "</ul>";
  51.  
  52.  
  53.     //Adding links if logged in or logged out
  54.     echo "<br>";
  55.     if(isset($uname)){ //if user logged in ; log out
  56.         if($role =="admin"){
  57.             //echo "<a href=uploadform.php>Upload Images</a>";
  58.             echo"<a href=uploadform.html>Upload Images</a>";
  59.             echo "<br>";
  60.  
  61.         }
  62.         echo "<br>";
  63.         echo "<a href=do_logout.php>Log Out</a>";
  64.         echo"<form action='index1.php' method='POST'>";
  65.  
  66. echo  "<select name = 'currency'>";
  67.  
  68. foreach ($arr as $key=>$value)
  69. {
  70.  
  71. echo "<option value ='".$key."'>".$value."</option>\n";
  72.  
  73.     }
  74.  
  75.     echo "</select><br>";
  76.     echo "<input type = 'submit' value = 'convert'>";    
  77.     echo "</form>";
  78.  
  79.     $cal = $cur->rateFromSGD($currency);
  80.     $look = $cur->lookup($currency);
  81.  
  82.  
  83.     echo "Currently you are using: ".$look;
  84.     echo"<br>";
  85.     echo "The exchange rate is ".$cal;
  86.  
  87.     }
  88.  
  89.     else{ //else: log in
  90.  
  91.         echo "<a href = login.html>Log In</a><br>";
  92.         echo "<a href = signupform.php>Sign Up</a><br>";
  93.  
  94.     }
  95.     echo"<img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo1.jpg' width='150' height='80'><br><br>";
  96.     echo"<img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo2.jpg' width='150' height='80'><br><br>";
  97.     echo"<img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/callaway.jpg' width='150' height='80'><br><br>";
  98.     echo"<img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo4.jpg' width='150' height='80'><br><br>";
  99.     echo"<img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo5.jpg' width='150' height='80'><br><br>
  100.     <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo6.jpg' width='150' height='80'><br><br>
  101.     <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo7.jpg' width='150' height='80'><br><br>
  102.     <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo8.jpg' width='150' height='80'><br><br>
  103.     <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo9.jpg' width='150' height='80'><br><br>
  104.     <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo10.jpg' width='150' height='80'><br><br>
  105.     <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo11.jpg' width='150' height='80'><br><br>
  106.     <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo12.jpg' width='150' height='80'><br><br>";
  107. echo"</td></table>";    
  108.  
  109.     ?>
  110. </div>
  111.  
  112.     <div id="maincol">
  113.     <form name = "form" method = "POST" action = "do_addcart.php" onSubmit = 'return validate_form ();'> 
  114.     <?php
  115.     $getName = $_GET['name'];
  116.  
  117.     if (isset($getName)){
  118.         $selPaint = "SELECT * from ladies where brand ='".$getName."'";
  119.  
  120.     }
  121.     else{
  122.         $selPaint = "SELECT * from ladies";
  123.     }
  124.  
  125. $execPaint = mysql_query($selPaint);
  126.     while($thisArt = mysql_fetch_array($execPaint)){
  127.  
  128.         $fName = $thisArt['filename'];
  129.         $id = $thisArt['id'];
  130.         $_SESSION['id']=$id;
  131.  
  132.      //echo "<input type='hidden' name='vin' value=$id>";
  133.  
  134.         echo"<table bgcolor='#FFFFFF' border='1' width='570' height='200' cellspacing='5'>";
  135.         $title=$thisArt['title'];
  136.      echo "<h3><td>".$title."</h3>";     
  137.  
  138.     $text=wordwrap($title,2,"<br />\n");
  139.  
  140.     echo "<a href =".$uploaddir.$fName.">";
  141.         echo "<img src=".$thumbdir."thumb_".$fName."></a><br>";
  142.  
  143.         $price=$thisArt['price'];
  144.      echo "<td><br><br><br>";    
  145.         $Des = "<h4>".$thisArt['description']."</h4><br>";
  146.         $text1=wordwrap($Des,60,"<br />\n");
  147.         echo"<h3>".$text1."</h3></td><br>";
  148.         /*if($role =="admin"){
  149.         echo "<td><a href=\"do_delete.php?id=".$id."\">Delete</a></td>";
  150.         echo "<td><a href=\"updatecontact.php?id=".$id."\">Update</a></td>";
  151.  
  152.         }*/
  153.     echo"</table>";
  154.         echo "<BR>";
  155.  
  156.         if (isset($_SESSION['userid'])) {
  157.  
  158.         if($role =="admin"){
  159.         //echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  160.         echo "<a href=\"do_delete.php?id=".$id."\">Delete</a>";
  161.         echo "&nbsp;&nbsp;";
  162.         echo "<a href=\"update.php?id=".$id."\">Update</a>";
  163.         echo "<br>";
  164.         echo "<br>";
  165.         }
  166.         $rprice=round($price,2);
  167.         if(isset($currency)){
  168.         $asd = $price*$cal;
  169.         $round=round($asd,2);
  170.        echo"<table>";
  171.        echo"<tr>";
  172.        echo"<td>";
  173.         echo "<input type = 'checkbox' value = '1' name = '".$id."'>Buy this poster. Currency: ".$look.". Price = $". $round;
  174.     }
  175.         else{
  176.             echo "<input type = 'checkbox' value = '1' name = '".$id."'>Buy this poster. Price = $ S.G ".$rprice;
  177.             echo "<br>";
  178.  
  179.             }
  180.  
  181.         }
  182.  
  183.     }
  184.  
  185.  
  186.     if (isset($_SESSION['userid'])) {
  187.         echo "<br>";
  188.         echo "<br>";
  189.         echo "<input type = 'submit' value = 'order'>";
  190.         echo "<br>";
  191.         echo "<br>";
  192.     }
  193.     //echo"<a href=.php>go back</a><br>";
  194.     //echo "<input type='hidden' name='vin' value=$id>";
  195.     ?>
  196.  
  197.  
  198. </form>
  199. </div>
  200. </body>
  201. </html>
  202.  
  203.  


the code in do_addcart.php is in the following:

Expand|Select|Wrap|Line Numbers
  1. :
  2. <?
  3.     ob_start();
  4.     session_start();
  5. ?>
  6. <html>
  7. <head>
  8. <link rel="stylesheet" type="text/css" href="shop.css" /><div id="h">Ladies' Apparels</div>
  9. <script language="JavaScript">
  10.  
  11. <!--
  12.  
  13. function validate_form ( )
  14. {
  15.     valid = true;
  16. alert (document.Lform.$quantity.selectedIndex);
  17.     if ( document.Lform.$quantity.selectedIndex == 0 )
  18.         {
  19.                 alert ( "Please select your quantity!" );
  20.                 Lform.$quantity.focus();
  21.                 valid = false;
  22.         }
  23.     else if ( document.Lform.$size.selectedIndex == 0 )
  24.         {
  25.                 alert ( "Please select your size!" );
  26.                 Lform.$size.focus();
  27.                 valid = false;
  28.         }
  29.             return valid;
  30. }
  31. //-->
  32. </script>
  33. </head>
  34. <body>
  35.     <div id="maincol">
  36.     <form name = "Lform" method = "POST" action = "do_addcart.php" onSubmit = 'return validate_form ();'> 
  37. <?
  38.     ob_start();
  39.     session_start();
  40.  
  41.     require("db.php");
  42.  
  43.     mysql_connect(MACHINE, USER, '');
  44.     mysql_select_db(DBNAME);
  45.  
  46.  
  47.     $userid = $_SESSION['userid'];
  48.  
  49.     $date=date("D j-M-Y G:i:s");
  50.     echo $date;
  51.     echo"<BR>";
  52.  
  53.    foreach ($_POST as $key => $value) {
  54.     echo "key: ".$key.", value: ".$value."<br>";
  55.         $sql = "INSERT INTO orders (imageid, userid, time) VALUES ('$key', '$userid', '$date')";
  56.         mysql_query($sql); 
  57.     }
  58.  
  59. echo "Please select your size and quantity for purchase:";
  60.     echo "<table border = '1'>";
  61.                 echo "<tr>";
  62.                 echo "<td><b>Title</b></td>";
  63.                 echo "<td><b>Brand</b></td>";
  64.                 echo "<td><b>Price</b></td>";
  65.                 echo "<td><b>Size</b></td>";
  66.                 echo "<td><b>Quantity</b></td>";
  67.                 echo "</tr>";
  68. $sql2="SELECT imageid FROM orders";
  69. $result=mysql_query($sql2);
  70. while($row = mysql_fetch_array($result)) {
  71.                 echo "<br>";
  72.                 $sql3="SELECT brand, price, title FROM ladies WHERE id=".$row['imageid'];
  73.                 $ImageResult = mysql_query($sql3);
  74.                 $ImageDetail = mysql_fetch_array($ImageResult);
  75.                 echo "<tr>";
  76.                 echo "<td>".$ImageDetail['title']."</td>";
  77.                 echo "<td>".$ImageDetail['brand']."</td>";
  78.                 echo "<td>".$ImageDetail['price']."</td>";
  79.                 echo"<td>";
  80.         echo"
  81.             <select id='size' name='$size' tabindex='11'>
  82.                             <option value='0'>---</option>
  83.                             <option value='1' >S</option>
  84.                             <option value='2'>M</option>
  85.                             <option value='3'>L</option>
  86.                             <option value='4'>XL</option>
  87.                     </select>
  88.                     </td>";     
  89.     //echo"&nbsp;&nbsp;&nbsp;&nbsp;";    
  90.                             $quantity=0;
  91.                         $quantity=$quantity+1;
  92.  
  93.     echo"
  94.         <td>
  95.             <select id='NO' name='$quantity' tabindex='11'>
  96.                             <option value='0'>---</option>
  97.                             <option value='1' >1</option>
  98.                             <option value='2'>2</option>
  99.                             <option value='3'>3</option>
  100.                             <option value='4'>4</option>
  101.                             <option value='5'>5</option>
  102.                             <option value='6'>6</option>
  103.                             <option value='7'>7</option>
  104.                             <option value='8'>8</option>
  105.                             <option value='9'>9</option>
  106.                             <option value='10'>10</option>
  107.                     </select>
  108.                     </td>"; 
  109.                  echo "</tr>";            
  110.                 }
  111.             echo "</table>";
  112.  
  113.  
  114.     //header('Refresh: 3; url=cart.php');
  115.     //echo "<meta http-equiv='refresh' content='5;url=http://google.com'>";
  116.     echo "<input type = 'submit' value = 'order'>";
  117.     echo"<BR>";
  118.     echo "Your order is being processed, you will be directed to your shopping cart soon";
  119.  
  120. ?>
  121. </body>
  122. </html>
  123.  
  124.  
i would like users to choose the items's respective quantity and size, but i don't know how to know which quantity and size is belong to which item. i think my naming may have problem since i all use "quantity" and "size" for every item. but i don't know how to sovle it. i have no clue of it. can help me with it. thanks in advance
Jul 7 '07 #4
ak1dnar
1,584 Recognized Expert Top Contributor
There are lots of Errors in your script.

  • You are trying to print $quantity, $size inside the HTML(Javascript ) code
    Note that PHP is executing in server side,not in the client side.if you need to print server side php varibles inside html coding, you may replace
Expand|Select|Wrap|Line Numbers
  1. document.Lform.$quantity.selectedIndex == 0
  2.  
with this

Expand|Select|Wrap|Line Numbers
  1. document.Lform.<?php $quantity ?>.selectedIndex == 0
  2.  
And Under those list menus why is that name attribute is set to $quantity,$size . From where it is coming from?
are you planing to set the same size and quantity for all purchased item(what are those item really).
Jul 8 '07 #5
kang jia
88 New Member
There are lots of Errors in your script.

  • You are trying to print $quantity, $size inside the HTML(Javascript ) code
    Note that PHP is executing in server side,not in the client side.if you need to print server side php varibles inside html coding, you may replace
Expand|Select|Wrap|Line Numbers
  1. document.Lform.$quantity.selectedIndex == 0
  2.  
with this

Expand|Select|Wrap|Line Numbers
  1. document.Lform.<?php $quantity ?>.selectedIndex == 0
  2.  
And Under those list menus why is that name attribute is set to $quantity,$size . From where it is coming from?
are you planing to set the same size and quantity for all purchased item(what are those item really).


hi, in fact i was writiing a loop, but i think i delete it befoer i post, originally, i wrtie
Expand|Select|Wrap|Line Numbers
  1. $quantity=0;
  2. $quantity=$quantity+1; // do the same for $size;
  3.  
i do in this is to let the drop down list of quantity and size have differe name, so that i may know which item user purchased according to which quantity and size name; something like quantity1=3, quantity2=5,etc .but finally i can not achieve it, i have only this kind of concept.is this concept correct?

in fact, i would like to know the quantity and size they choosed accorrding to the different items they buy and it is a must for them to select quantity and size from drop down list for every item they buy.

i don;t know how should i write the code so that i will know which quantity and size user selected is corresponding to which item they buy and there is also a validation so that user will not forget to select their item's quantity and size.

can help me with these part of the code, thank you very much. i am very frustrated as the project deadline is near. thank you very much for your kind help :)
Jul 8 '07 #6
ak1dnar
1,584 Recognized Expert Top Contributor
Can I see the Table structure first.Then I might be able to help.

Or else go for a re-structuring you tables and Apps by your self.

Example:
  • From Products table list all the products to page(s) with the unique product_id
    EX: 1001,1002,1003, 1004,....,n
  • Insert the selected products to orders table by sending the product_id to the Orders table
    Ex: user select the product 1001 and 1004, then insert them to orders table.
  • Once you came to this stage.(update shopping cart)
    User can Insert Number of Items and size for 1001 and 1004
You can put those size and Quantity in side the while loop and display the corresponding list menus for both selected products.
Ex:

1001 - size_list_menu - qty_list_menu
1004 - size_list_menu - qty_list_menu

[You can display the product Image/Name instead of Product_id to the User]
Once user select the size and Qty update them to Orders Table again.
So now for all the purchased item(s) you have.

ProductNumber
Size
Qty

That's it, Then proceed with your Payment gateway.
Jul 9 '07 #7
kang jia
88 New Member
Can I see the Table structure first.Then I might be able to help.

Or else go for a re-structuring you tables and Apps by your self.

Example:
  • From Products table list all the products to page(s) with the unique product_id
    EX: 1001,1002,1003, 1004,....,n
  • Insert the selected products to orders table by sending the product_id to the Orders table
    Ex: user select the product 1001 and 1004, then insert them to orders table.
  • Once you came to this stage.(update shopping cart)
    User can Insert Number of Items and size for 1001 and 1004
You can put those size and Quantity in side the while loop and display the corresponding list menus for both selected products.
Ex:

1001 - size_list_menu - qty_list_menu
1004 - size_list_menu - qty_list_menu

[You can display the product Image/Name instead of Product_id to the User]
Once user select the size and Qty update them to Orders Table again.
So now for all the purchased item(s) you have.

ProductNumber
Size
Qty

That's it, Then proceed with your Payment gateway.

i think i have the same concept as you when i am doing this, but my problem is how should i validate user's selection of their selected item's size and quantity as users may forget to choose some of them. my validation now is
Expand|Select|Wrap|Line Numbers
  1. <?
  2.     ob_start();
  3.     session_start();
  4. ?>
  5. <html>
  6. <head>
  7. <link rel="stylesheet" type="text/css" href="shop.css" /><div id="h">Ladies' Apparels</div>
  8. <script language="JavaScript">
  9.  
  10. <!--
  11.  
  12. function validate_form ( )
  13. {
  14. valid = true;
  15. alert (document.Lform.quantity.selectedIndex);
  16. if ( document.Lform.quantity.selectedIndex == 0 )
  17. {
  18. alert ( "Please select your quantity!" );
  19.                 Lform.quantity.focus();
  20. valid = false;
  21. }
  22.     else if ( document.Lform.size.selectedIndex == 0 )
  23. {
  24. alert ( "Please select your size!" );
  25.                 Lform.size.focus();
  26. valid = false;
  27. }
  28.             return valid;
  29. }
  30.  
  31. </script>
  32. </head>
  33. <body>
  34. <?
  35.     ob_start();
  36.     session_start();
  37.  
  38.     require("db.php");
  39.  
  40.     mysql_connect(MACHINE, USER, '');
  41.     mysql_select_db(DBNAME);
  42.  
  43.  
  44.     $userid = $_SESSION['userid'];
  45.  
  46.     $date=date("D j-M-Y G:i:s");
  47.     echo $date;
  48.     echo"<BR>";
  49.  
  50. foreach ($_POST as $key => $value) {
  51.     echo "key: ".$key.", value: ".$value."<br>";
  52.         $sql = "INSERT INTO orders (imageid, userid, time) VALUES ('$key', '$userid', '$date')";
  53.         mysql_query($sql); 
  54.     }
  55. $sql2="SELECT imageid FROM orders";
  56. $result=mysql_query($sql2);
  57. while($row = mysql_fetch_array($result)) {
  58.                 echo "<br>";
  59.                 $id=$row['imageid'];
  60.                 $_SESSION['id1']=$id;
  61.                 $sql3="SELECT brand, price, title FROM ladies WHERE id=".$row['imageid'];
  62.                 $ImageResult = mysql_query($sql3);
  63.                 $ImageDetail = mysql_fetch_array($ImageResult);
  64.                 echo "<tr>";
  65.                 echo "<td>".$ImageDetail['title']."</td>";
  66.                 echo "<td>".$ImageDetail['brand']."</td>";
  67.                 echo "<td>".$ImageDetail['price']."</td>";
  68.                 echo"<td>";
  69.     echo"
  70.             <select id='size' name='size' tabindex='11'>
  71.                             <option value='0'>---</option>
  72.                             <option value='1' >S</option>
  73.                             <option value='2'>M</option>
  74.                             <option value='3'>L</option>
  75.                             <option value='4'>XL</option>
  76.                     </select>
  77.                     </td>";     
  78.     //echo"&nbsp;&nbsp;&nbsp;&nbsp;";    
  79.  
  80.  
  81.     echo"
  82.         <td>
  83.             <select id='NO' name='quantity' tabindex='11'>
  84.                             <option value='0'>---</option>
  85.                             <option value='1' >1</option>
  86.                             <option value='2'>2</option>
  87.                             <option value='3'>3</option>
  88.                             <option value='4'>4</option>
  89.                             <option value='5'>5</option>
  90.                             <option value='6'>6</option>
  91.                             <option value='7'>7</option>
  92.                             <option value='8'>8</option>
  93.                             <option value='9'>9</option>
  94.                             <option value='10'>10</option>
  95.                     </select>
  96.                     </td>"; 
  97. ?>
  98. </body>
  99. </html>
  100.  
however, it seems does not work at all, i think because of the naming problem. as every item is using the name of 'quantity' and 'size', so the program don;t know which quantity and size choosen is belong to which item. so how should i sovle this? this is the main problem. thanks :)

PS. my product id is atom increment, the other fields are brand, price,descripti on,etc. in my orders table, i got product id as foreign key, userid as foreign key. the rest of field is time, quantity, size.

thank you very much for your kind help. this is a bit urgent as my project's deadline is very near. if possible, please reply me ASAP. thanks:)
Jul 10 '07 #8
ak1dnar
1,584 Recognized Expert Top Contributor
Since this is a shopping cart you can set some default size and Quantity for a selected item always.
Ex:
Qty always set to 1
Size set to S

For a Customer do we need to display 0 s or blanks for products, I dnt think so.Then no need of validation at all.

Still if you expecting validation just give me some times.
Thanks!
-Ajaxrand
Jul 10 '07 #9
kang jia
88 New Member
Since this is a shopping cart you can set some default size and Quantity for a selected item always.
Ex:
Qty always set to 1
Size set to S

For a Customer do we need to display 0 s or blanks for products, I dnt think so.Then no need of validation at all.

Still if you expecting validation just give me some times.
Thanks!
-Ajaxrand

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 quanity 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. :)
Jul 11 '07 #10

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
2461
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
4101
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
1446
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
2691
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
3687
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
9647
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
10164
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
10110
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,...
1
7512
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
6745
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();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4066
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.