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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb return values from textfield retrieved from database php

    here's the can.php

    <?php
    $conn=odbc_connect('firebird','SYSDBA','masterkey');
    if (!$conn)
    {exit("Connection Failed: " . $conn);}
    $sql="SELECT * FROM CANNED";
    $rs=odbc_exec($conn,$sql);
    if (!$rs)
    {exit("Error in SQL");}
    echo "<table class='tbcanned' cellpadding='5' cellspacing='5'><tr>";
    echo "<th>PRODUCT</th>";
    echo "<th>QUANTITY</th>";
    echo "<th>PRICE</th>";
    echo "<th>DESCRIPTION</th>";
    echo "<th>ADD TO CART</th></tr>";
    $i=1;
    while (odbc_fetch_row($rs))
    {
    $id=odbc_result($rs,"ID");
    $name=odbc_result($rs,"NAME");
    $quantity=odbc_result($rs,"QUANTITY");
    $price=odbc_result($rs,"PRICE");
    $description=odbc_result($rs,"DESCRIPTION");
    echo "<tr><td style='background-image:url(../_image/tealGradient.png)'><input type='text' name=name value='$name' class='name'>";
    echo "<br";
    echo "<tr><td><input type='text' value=0 name='quantity[$i]' class='quantity'>";
    echo "<br";
    echo "<tr><td><input type='text' value='$price' name='price[]' class='price'>";
    echo "<br";
    echo "<tr><td>$description";
    echo "<br";
    echo "<tr><td><input type='checkbox' name='checkbox[]' value='$name'>";
    echo "<br";
    echo "</table>";
    $i++;
    }
    odbc_close($conn);
    echo "</table>";

    ?>



    here's the cart.php

    <?php

    $name = $_POST['name'];
    $quantity = $_POST['quantity'];
    $checkbox = $_POST['checkbox'];
    $price = $_POST['price'];


    if(is_array($checkbox)){
    foreach($checkbox as $key=>$value){

    echo "$value.<br/>";
    echo "$price";
    }
    if (is_array($quantity)){

    foreach($quantity as $key=>$item_qty){
    $item_qty = intval($item_qty);
    if($item_qty>0){
    echo "$item_qty.<br/>";
    }



    }
    }

    }


    ?>


    i only want to display the value of price base on the checkbox selected and compute the total of it by $total = $quantity * $price

    tnx in advance anyone. . .

  • #2
    Regular Coder
    Join Date
    Jan 2012
    Posts
    271
    Thanks
    2
    Thanked 65 Times in 65 Posts
    if you can't be bothered posting your code in a neat readable manner, eg using the php/code feature...

    there's a very good chance no-one will be bothered trying to help you...

    just saying...
    hey... it's a sig..

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    also can.php is very badly written

    none of the table columns or rows have closing tags, there shouldnt be line breaks in there
    and the table is closed twice.

    there are many problems with it to fix before we can edit it

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    The table is closed multiple times, once per row, then another time for good measure.

  • Users who have thanked Keleth for this post:

    Arcticwarrio (07-10-2012)

  • #5
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    can.php

    PHP Code:
    <?php
    $conn
    =odbc_connect('firebird','SYSDBA','masterkey');
    if (!
    $conn){exit("Connection Failed: " $conn);}
    $sql="SELECT * FROM CANNED";
    $rs=odbc_exec($conn,$sql);
    if (!
    $rs){exit("Error in SQL");}
    echo 
    "
    <table class='tbcanned' cellpadding='5' cellspacing='5'>
    <tr>
    <th>PRODUCT</th>
    <th>QUANTITY</th>
    <th>PRICE</th>
    <th>DESCRIPTION</th>
    <th>ADD TO CART</th>
    </tr>"
    ;
    $i=1;
    while (
    odbc_fetch_row($rs)){
    $id=odbc_result($rs,"ID");
    $name=odbc_result($rs,"NAME");
    $quantity=odbc_result($rs,"QUANTITY");
    $price=odbc_result($rs,"PRICE");
    $description=odbc_result($rs,"DESCRIPTION");
    echo 
    "
    <tr>
    <td style='background-image:url(../_image/tealGradient.png)'><input type='text' name=name value='$name' class='name'></td></tr>
    <tr><td><input type='text' value=0 name='quantity[$i]' class='quantity'></td></tr>
    <tr><td><input type='text' value='$price' name='price[]' class='price'></td></tr>
    <tr><td><textarea name='description[]'>$description</textarea></td></tr>
    <tr><td><input type='checkbox' name='checkbox[]' value='$name'></td></tr>"
    ;
    $i++;
    }
    odbc_close($conn);
    echo 
    "</table>";
    ?>


  •  

    Posting Permissions

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