transaction.php page catches the sessions, but
I have problems displaying quantities and then multiplying them with product costs on next page updatetrans.php.
I manage for it to echo correct totals, but all in the wrong places, and duplicated.
My "Foreach" statement must be the problem, but I have mind block right now.
Any suggestions?
Here's my 2 pages:
TRANSACTION.PHP
<?php
session_start();
//unset($SESSION['checked']);
$SESSION['UserName'] = $POST['name'];
$SESSION['Surname'] = $POST['surname'];
$SESSION['prod_CodeName'] = $POST['prod_code_name'];
$SESSION['prod_cost'] = $POST['prodcost'];
$SESSION['checked'] = $POST['checked'];
$SESSION['qty'] = $_POST['qty'];
echo("Welcome ".$SESSION['UserName']." ".$SESSION['Surname'].".");
$conn= mysql_connect( "localhost", "user", "password" );
$rs = mysql_select_db( "mydatabase", $conn);
$qry1 = mysql_query("Select prodid, proddescript, picpath, prod_code_name, prodcost, flag from product order by proddescript");
$rs = mysql_query($qry1, $conn);
echo("<form name=\"Submit\" method=\"post\" action=\"updatetrans.php\">");
echo("<table width=\"100%\" border=\"2\">");
echo("<tr><th>Picture:</th>");
echo("<th>Product Code Name:</th>");
echo("<th>Description:</th>");
echo("<th>Price:</th>");
echo("<th>Purchase ?:</th>");
echo("<th>Quantity:</th></tr>");
while ($resrow = mysql_fetch_array($qry1)){
$SESSION['prod_id'] = $resrow[0];
$SESSION['prod_desc'] = $resrow[1];
$SESSION['pic_path'] = $resrow[2];
$SESSION['prod_CodeName'] = $resrow[3];
$SESSION['prod_cost'] = $resrow[4];
$SESSION['qty'] = $resrow[6];
echo("<tr>");
echo("<td><img src=".$SESSION['pic_path']." width=\"45\" height=\"45\"></td>");
echo("<td>".$SESSION['prod_CodeName']."</td>");
echo("<td>".$SESSION['prod_desc']."</td>");
echo("<td>".$SESSION['prod_cost']."</td>");
echo("<td><input name=\"checked[]\" type=\"checkbox\" value=\"".$SESSION['prod_id']."\"></td>");
echo("<td><input name=\"qty[]\" type=\"textbox\" value=\"".$POST['qty']."\"></td>");
echo("</tr>");
}
echo("</table>");
echo("<center><input name=\"btnTest\" type=\"submit\" value=\"Submit\"></center>");
echo("</form>");
?>
UPDATETRANS.PHP
<?php
session_start();
echo("Welcome ".$SESSION['UserName']." ".$SESSION['Surname'].".");
$conn= @mysql_connect( "localhost", "user", "password" )
or die( "Could not Connect to Database" );
$rs = @mysql_select_db( "mydatabase", $conn )
or die( "Could not Select Database" );
//$SESSION['qty'] = $POST['qty'];
//$value = $_POST['qty'];
if (isset($_POST['checked'])){
foreach($_POST['checked'] as $value){
if (isset($_POST['qty'])){
foreach($_POST['qty'] as $valueq){
echo("<center><table border=\"1\">");
$qry1 = mysql_query("Select prodid, proddescript, picpath, prod_code_name, prodcost, flag, Qty from product where prodid =".$value);
$rs = mysql_query($qry1, $conn);
while ($resrow = mysql_fetch_array($qry1))
{
$Stotal = $resrow[4] * $valueq;
echo("<tr>");
echo("<td><img src=".$resrow[2]." width=\"45\" height=\"45\"></td>");
echo("<td>".$resrow[3]."</td>");
echo("<td>".$resrow[1]."</td>");
echo("<td>R ".$resrow[4]."</td>");
echo("</tr>");
}
echo("<tr>");
echo("<td></td>");
echo("<td></td>");
echo("<td>Total</td>");
echo ("<td> $Stotal </td>");
echo("</tr>");
}}}}
echo("</table>");
?>