bluedollar
Programmer
I have some code that allows users to view their shopping cart (which can contain social event tickets, conference tickets and misc items to do with a conference), as shown below:
=======================================================
function displaychk() {
echo'<form action="checkoutscript.php" METHOD=POST>';
echo'<table border="0">';
echo'<tr bgcolor="#999999"><th colspan="3" align="left">Check Out</th></tr>';
echo'<tr><td><br></td></tr>';
echo'<tr><th width="50%" bgcolor="#999999" align="left">Description</th><th bgcolor="#999999" align="left">Qty</th><th bgcolor="#999999" align="left">Price</th></tr>';
if ($_SESSION['accep'] != ""
{
$aid = $_SESSION['accep'];
$SQL = "select description from prices where prices_id = '$aid'";
$description = $this->obconnect->selectcol($SQL,"description"
;
$SQL = "select cost from prices where prices_id = '$aid'";
$itemcost = $this->obconnect->selectcol($SQL,"cost"
;
echo'<tr><td>Ticket - '.$description.'</td><td>1</td><td>£'.$itemcost.'</td></tr>';
}
if ($_SESSION['social'] != ""
{
$sid = $_SESSION['social'];
$SQL = "select name from social where social_id = '$sid'";
$description = $this->obconnect->selectcol($SQL,"name"
;
$SQL = "select price from social where social_id = '$sid'";
$itemcost = $this->obconnect->selectcol($SQL,"price"
;
if ($_SESSION['social_qty'] != ""
{ $sqty = $_SESSION['social_qty']; }
else { $sqty = 1;}
echo'<tr><td>Social Event - '.$description.'</td><td><input type="text" size="3" name="socqty" value="'.$sqty.'"></td>';
$totalcost = $itemcost * $sqty;
echo'<td>£'.$totalcost.'</td></tr>';
}
if ($_SESSION['proc'] != ""
{
$sid = $_SESSION['proc'];
$esid = explode(" ", $sid);
if ($_SESSION['proc_qty'] != ""
{
$epqty = explode (" ", $_SESSION['social_qty'] );
}
$counter = 0;
foreach ($esid as $val) {
$SQL = "select name from proceedings where proc_id = '$val'";
$name = $this->obconnect->selectcol($SQL,"name"
;
$SQL = "select price from proceedings where proc_id = '$val'";
$itemcost = $this->obconnect->selectcol($SQL,"price"
;
if ($_SESSION['proc_qty'] != ""
{
$totalcost = $itemcost * $eqty[$counter];
}
else { $totalcost = $itemcost * 1; }
$qname = 'proc';
$qname .= $counter;
echo'<tr><td>Proceeding - '.$name.'</td><td><input type="text" size="3" name="'.$qname.'" value="1"></td><td>£'.$totalcost.'</td></tr>';
$counter++;
}
}
echo'<tr><td><input type="submit" name="recalc" value="Recalculate Prices"></td><td><input type="submit" name="purchase" value="Purchase"></td></tr>';
echo'</table>';
echo'</form>';
}
==========================================================
On the form there is a recalculate quantities button that calls a script which saves the quantities from the form quantity text boxes into session variables, when the function above is then reloaded the corresponding prices are calculated.
This works fine for social event tickets and coference tickets, however because misc conference items may consist of > 1 item I do not know how to obtain the value of the quantity text boxes on the form, they are named:
proc0
proc1
proc2
procn
however do not know how to obtain these variables from the script that is called from the form.
QUESTION
1) Does anyone have any ideas about solving the above problem?
2) And ways in which the code could generally be improved.
Any help would be greatly appreciated.
Thanks
Dan
=======================================================
function displaychk() {
echo'<form action="checkoutscript.php" METHOD=POST>';
echo'<table border="0">';
echo'<tr bgcolor="#999999"><th colspan="3" align="left">Check Out</th></tr>';
echo'<tr><td><br></td></tr>';
echo'<tr><th width="50%" bgcolor="#999999" align="left">Description</th><th bgcolor="#999999" align="left">Qty</th><th bgcolor="#999999" align="left">Price</th></tr>';
if ($_SESSION['accep'] != ""

$aid = $_SESSION['accep'];
$SQL = "select description from prices where prices_id = '$aid'";
$description = $this->obconnect->selectcol($SQL,"description"

$SQL = "select cost from prices where prices_id = '$aid'";
$itemcost = $this->obconnect->selectcol($SQL,"cost"

echo'<tr><td>Ticket - '.$description.'</td><td>1</td><td>£'.$itemcost.'</td></tr>';
}
if ($_SESSION['social'] != ""

$sid = $_SESSION['social'];
$SQL = "select name from social where social_id = '$sid'";
$description = $this->obconnect->selectcol($SQL,"name"

$SQL = "select price from social where social_id = '$sid'";
$itemcost = $this->obconnect->selectcol($SQL,"price"

if ($_SESSION['social_qty'] != ""

else { $sqty = 1;}
echo'<tr><td>Social Event - '.$description.'</td><td><input type="text" size="3" name="socqty" value="'.$sqty.'"></td>';
$totalcost = $itemcost * $sqty;
echo'<td>£'.$totalcost.'</td></tr>';
}
if ($_SESSION['proc'] != ""

$sid = $_SESSION['proc'];
$esid = explode(" ", $sid);
if ($_SESSION['proc_qty'] != ""

$epqty = explode (" ", $_SESSION['social_qty'] );
}
$counter = 0;
foreach ($esid as $val) {
$SQL = "select name from proceedings where proc_id = '$val'";
$name = $this->obconnect->selectcol($SQL,"name"

$SQL = "select price from proceedings where proc_id = '$val'";
$itemcost = $this->obconnect->selectcol($SQL,"price"

if ($_SESSION['proc_qty'] != ""

$totalcost = $itemcost * $eqty[$counter];
}
else { $totalcost = $itemcost * 1; }
$qname = 'proc';
$qname .= $counter;
echo'<tr><td>Proceeding - '.$name.'</td><td><input type="text" size="3" name="'.$qname.'" value="1"></td><td>£'.$totalcost.'</td></tr>';
$counter++;
}
}
echo'<tr><td><input type="submit" name="recalc" value="Recalculate Prices"></td><td><input type="submit" name="purchase" value="Purchase"></td></tr>';
echo'</table>';
echo'</form>';
}
==========================================================
On the form there is a recalculate quantities button that calls a script which saves the quantities from the form quantity text boxes into session variables, when the function above is then reloaded the corresponding prices are calculated.
This works fine for social event tickets and coference tickets, however because misc conference items may consist of > 1 item I do not know how to obtain the value of the quantity text boxes on the form, they are named:
proc0
proc1
proc2
procn
however do not know how to obtain these variables from the script that is called from the form.
QUESTION
1) Does anyone have any ideas about solving the above problem?
2) And ways in which the code could generally be improved.
Any help would be greatly appreciated.
Thanks
Dan