...

View Full Version : return values from textfield retrieved from database php



skitband
07-10-2012, 07:56 AM
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. . .

jmj001
07-10-2012, 08:39 AM
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...

Arcticwarrio
07-10-2012, 04:43 PM
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

Keleth
07-10-2012, 04:48 PM
The table is closed multiple times, once per row, then another time for good measure.

Arcticwarrio
07-10-2012, 04:48 PM
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>
<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>";
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum