Jump to content

Recommended Posts

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.

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

 

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>";

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>

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

 

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.