Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Shopping Basket / PHP Database

    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.

  • #2
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,560
    Thanks
    76
    Thanked 105 Times in 104 Posts
    Quote Originally Posted by greenroy View Post
    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
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #4
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Any hints how to use JS for that?

    *Edit - managed to finally get it working.
    Last edited by greenroy; 04-20-2012 at 09:07 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •