I’m developing a site for a friend that is only to be used by his staff, not customers.
Part of this is a form to add items to an order. I have done this in the following manner:
The code is as follows:
[code]<?
// connect to db
include(“dbinfo.inc.php”);
$connection = mysql_connect($server,$username,$password);
if (!$connection){
echo mysql_errno().": “.mysql_error().”
";
exit;
}
if(!mysql_select_db($database)){
echo(“Database not found
”);
}
//RETURN RESULT
$result = mysql_query (“SELECT ID,Item,Price,SortOrder FROM products ORDER BY SortOrder”);
$total = mysql_num_rows($result);
?>
<? if($total>0) { ?> <? // print table header echo("
Item | Price | Quantity |
---|---|---|
" . $row[“Item”] . “ | ”);" . $row[“Price”] . “ | ”);<? echo " |
mysql_close();
?>
As you can see, I used:
<td><input type="text" name="Quantity<?php echo $row[SortOrder];?>"" value ="0" size="5" /></td>
to create input boxes named Quantity1, Quantity2 etc.
I want to use that data in a shopping cart style, i.e. the items add to a cart. I made a quick test with viewcart.php which looks like this:
[code]<?
include(“dbinfo.inc.php”);
$connection = mysql_connect($server,$username,$password);
if (!$connection){
echo mysql_errno().": “.mysql_error().”
";
exit;
}
if(!mysql_select_db($database)){
echo(“Database not found
”);
}
//RETURN RESULT
$result = mysql_query (“SELECT ID,Item,Price,SortOrder FROM products ORDER BY SortOrder”);
$total = mysql_num_rows($result);
?>
<? if($total>0) { // print table header echo("
Item | Price | Quantity |
---|---|---|
" . $row["Item"] . " | "); echo("" . $row["Price"] . " | "); echo("" . $_POST[$q.$s] . " | "); echo ("
TOTAL: | " . $t . " |
I’m sure this isn’t a good method, although it seems to be working. I’ve looked into sessions, but can’t get my head round them! Could someone advise me?
Many thanks in advance!