bluestreak101 Posted April 17, 2012 Share Posted April 17, 2012 Hi all, I'm a bit of a newbie to this type of website and would be extremely grateful for any help on this as it's causing considerable headaches! I've been working on an e-commerce (Online Shop) website based on the site found here: http://www.phpwebcommerce.com/ I have been building it into a template from the original shop that was essentially a static website with links to paypal for the cart etc. Now I am trying to add an extra function to the site but cant get my head around the logic to making this work and I know it can be done! The shop is to sell mainly shoes with some accessories. So I understand that shoes obviously come in a variety of sizes, and each size needs to have its own product ID in the MySQL DB so I can show whether it is in stock etc. What I cant figure out is how to firstly make an easy way of adding the shoes different sizes (for eg 10 shoes of the same type in sizes 40-49) to the DB in one hit instead of filling in the same form 10 times but with different sizes. I have the simple form already made and working successfully. My thoughts are to add check box in the form to say I'm adding multiple shoes that tells the process to look for values in text areas for starting shoe size and last shoe size. The process then takes the start size from the end size giving the number of times to loop the process. It then loops the process for each size using the same information... Logically this works but I'm not sure how to code this on what I have. I have attached the files used directly in this. Secondly how do I group the shoes on the front end. Now each product on the front end currently will display a simple message instead of add to cart when the stock = 0, or the product has been made as available on request. I would like to group the shoes of the same type to have a drop down menu showing the available sizes. When a size is selected it needs to query the DB for available stock and either show the 'Add to cart' or 'Call to order' options. Anything else you might need to help with this let me know. I'm keen to get this bit done so I can get the site live! Thanks in advance 18089_.php 18090_.php Quote Link to comment https://forums.phpfreaks.com/topic/261077-php-commerce-help/ Share on other sites More sharing options...
Drummin Posted April 17, 2012 Share Posted April 17, 2012 I'm not going to go modify your code, but here's a simple example of how this might be done. <?php if (isset($_POST['NewShoe'])){ $insert=""; $sizefrom=trim($_POST['sizefrom']); $sizeto=trim($_POST['sizeto']); $size=$sizefrom; $newshoe=mysql_real_escape_string(trim($_POST['shoename'])); if (!empty($sizeto) && $sizeto>$sizefrom){ WHILE($size<=$sizeto){ $insert.="('$newshoe','$size')"; $insert.=($size<$sizeto ? ',' : ''); $size++; } }else{ $insert.="('$newshoe','$size')"; } $sql="INSERT INTO `shoetable` (shoename, shoesize) VALUES $insert"; mysql_query($sql) or trigger_error($sql . ' has encountered and error<br />' . mysql_error()); } ?> <html> <head> <style type="text/css"> .width70{ width:70px; } </style> <body> <form action="" method="post"> Shoe Name: <input type="text" name="shoename" /><br /> Size: <input type="text" name="sizefrom" class="width70" /> To: <input type="text" name="sizeto" class="width70" /><br /> <input type="submit" name="NewShoe" value="Add New Shoe" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/261077-php-commerce-help/#findComment-1338011 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.