By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,592 Members | 1,931 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,592 IT Pros & Developers. It's quick & easy.

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

P: 88
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
Share this Question
Share on Google+
14 Replies


ak1dnar
Expert 100+
P: 1,584

ak1dnar
Expert 100+
P: 1,584
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

P: 88
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
Expert 100+
P: 1,584
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

P: 88
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
Expert 100+
P: 1,584
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

P: 88
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,description,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
Expert 100+
P: 1,584
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

P: 88
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

ak1dnar
Expert 100+
P: 1,584
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

P: 88
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
Expert 100+
P: 1,584
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

P: 88
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
Expert 100+
P: 1,584
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

Post your reply

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