wkdown Posted June 18, 2007 Share Posted June 18, 2007 Hello all, I need some help. http://heatingonline.com/UK/order.php I am using an SQL query to populate a table with product data. The form is processed by another file. The buttons after each item are SUBMIT buttons. I want to have the user click the appropriate button and it sends that particular items ID value on for processing. The only way I found to do that is to have the submit button's value be the ID; which of course displays that ID instead of a "Proceed to Checkout >" label. I have tried a HIDDEN value inside my FOREACH loop but it returns EVERY ID not a particular one. Any help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/56059-multiple-submit-buttons-on-shopping-cart-form/ Share on other sites More sharing options...
liam1412 Posted June 18, 2007 Share Posted June 18, 2007 You could always just use a URL instead of a form <a href="processing.php?productid=<?php echo $productid; ?>">Add To Cart</a> Then in processing.php use GET to query the URL. Don't forget that what you receive over a URL needs to be checked. $productid= $_GET['productid']; //check to see if its what you expect if(!is_numeric($productid)){ Echo 'The product Id is invalid. Was this a feeble attempt at SQL injection'; } else { REST OF PROCESSING HERE } You can then change the link to an image and use javascript for the hover or click effects Quote Link to comment https://forums.phpfreaks.com/topic/56059-multiple-submit-buttons-on-shopping-cart-form/#findComment-276855 Share on other sites More sharing options...
wkdown Posted June 18, 2007 Author Share Posted June 18, 2007 That sounds good but the problem is I am sending more information through the form than just the ID. Is my only option then putting ALL the post data into that url link? a la echo "<a href='process.php?productid=" . $id . "&name=" . $name . "&email=" . $email . "'> Process </a>"; Quote Link to comment https://forums.phpfreaks.com/topic/56059-multiple-submit-buttons-on-shopping-cart-form/#findComment-276871 Share on other sites More sharing options...
liam1412 Posted June 18, 2007 Share Posted June 18, 2007 Well Im pretty noob as well but thats the only solution I can think of. Why do you need to send more data? Quote Link to comment https://forums.phpfreaks.com/topic/56059-multiple-submit-buttons-on-shopping-cart-form/#findComment-276874 Share on other sites More sharing options...
wkdown Posted June 18, 2007 Author Share Posted June 18, 2007 I know this method is retarded but its what they want... page a: contact info (name, phone, email, zip) page b: [must have gone through page 'a' first] product info (product id) along with the previous info page c: [confirmation] adds data to a database and uses PHP to send a confirm email to both user and company hub account There's no logging in and no actual purchase online (customer is contacted by phone or email) so I want to keep the code simple. Meaning stay away from cookies and session variables if possible If seeing the current code helps... <form action="confirmation.php" method="post"> <input type="hidden" name="cust_fname" value="<? echo $_POST['cust_fname']; ?>" /> <input type="hidden" name="cust_sname" value="<? echo $_POST['cust_sname']; ?>" /> <input type="hidden" name="postcode" value="<? echo $_POST['postcode']; ?>" /> <input type="hidden" name="email" value="<? echo $_POST['email']; ?>" /> <input type="hidden" name="phone" value="<? echo $_POST['phone']; ?>" /> <div id="products"> <p>Please select the product you are interested in</p> <table border="1"> <tr> <td>CATEGORY</td> <td>SIZE (m²)</td> <td>OUTPUT (W)</td> <td>PRICE (£)</td> <td> </td> <td>ADD</td> </tr> <? $our_products = query("SELECT * FROM products_uk ORDER BY category ASC"); foreach ($our_products as $ourProduct) { echo "<tr>\n"; echo "<td>" . $ourProduct['category'] . "</td>\n"; echo "<td>" . $ourProduct['size'] . "</td>\n"; echo "<td>" . $ourProduct['output'] . "</td>\n"; echo "<td>" . $ourProduct['price'] . "</td>\n"; echo "<td> </td>"; echo "<td><input type='submit' name='id' value='" . $ourProduct['id'] . "' /></td>\n"; echo "</tr>\n"; } ?> </table> </div> </form> Quote Link to comment https://forums.phpfreaks.com/topic/56059-multiple-submit-buttons-on-shopping-cart-form/#findComment-276883 Share on other sites More sharing options...
liam1412 Posted June 18, 2007 Share Posted June 18, 2007 Well its a bit clumsy but you could set up a table in your db called temp info. You could then insert the details into that as you go then transfer the details into your proper table on completion. Remebering to delete from this temp table when you've finished. Are you noob or just looking for a solution So Quote Link to comment https://forums.phpfreaks.com/topic/56059-multiple-submit-buttons-on-shopping-cart-form/#findComment-276889 Share on other sites More sharing options...
wkdown Posted June 18, 2007 Author Share Posted June 18, 2007 I believe I have it figured out. What I did is, within my FOREACH loop, I gave each product its own <form> with a Submit button and a hidden value with the id. This works. I'm thinking that using multiple forms like that is not good coding practice (i.e. bad juju) so I'd still like to know if anyone has a more appropriate method Quote Link to comment https://forums.phpfreaks.com/topic/56059-multiple-submit-buttons-on-shopping-cart-form/#findComment-276998 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.