...

View Full Version : Shopping Basket / PHP Database



greenroy
04-18-2012, 06:17 PM
Hello,

I have been trying to find a solution for hours now and have scrawled through what seems like thousands of internet pages to no avail.

I have a project to create. I have successfully created a database that displays products (fake) which people can add to the basket.

The help I need is with variables from a drop down selection box and SQL query. For example my drop down menu is linked successfully with the items from the database. When you select the item I then want that item to be assigned to a variable so an SQL query can be ran to find the price of that product.

The SQL statement works if I assign text to the variable, but I want to assign the drop down variable to another variable - if that makes sense?

$price = mysql_query("SELECT Price FROM groceries where Product='". $var."' ");

Above is my SQL statement using the $var variable. If i put $var = "Peanuts" then the SQL statement works fine but that would mean that every product added to the shopping basket would have the price of peanuts.

<FORM NAME="order" method="POST" action="#">
Quantity:
<input type=text size=2 maxlength=3 name=QUANTITY onChange='this.value=CKquantity(this.value)' value="1">
<select name="NAME">
<?php
while ($line = mysql_fetch_array($product, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line['Product'];?>"> <?php echo $line['Product'];?>
<?php
}
?>
</select>
<?php
$var = $_POST['NAME'];
?>

<select name="PRICE">
<?php

while ($line2 = mysql_fetch_array($price, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line2['Price'];?> "> <?php echo $line2['Price'];?> </option>
<?php
}
?>
</select>
<input type=button value=' Add to Cart ' onClick='AddToCart(this.form)'>
</form>

Any help?

Thanks in advance,
Nathan.

greenroy
04-19-2012, 04:59 PM
Thanks for posting the response.

I'll create a product ID field in my database and assign each product a unique number.

So the code that you supplied, will that act as a dynamic dropdown box? So if an item is selected in the first dropdown list, it would change the values of the second dropdown list based on the input of the first?

Thanks,
Nathan

myfayt
04-19-2012, 08:55 PM
Thanks for posting the response.

I'll create a product ID field in my database and assign each product a unique number.

So the code that you supplied, will that act as a dynamic dropdown box? So if an item is selected in the first dropdown list, it would change the values of the second dropdown list based on the input of the first?

Thanks,
Nathan

Use Javascript for that

greenroy
04-19-2012, 09:04 PM
Any hints how to use JS for that?

*Edit - managed to finally get it working.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum