
March 26th, 2008, 02:41 AM
|
|
Registered User
|
|
Join Date: Mar 2008
Posts: 1
Time spent in forums: 42 m 50 sec
Reputation Power: 0
|
|
|
Send multi data than insert in db?
Hi all!
I have a shop script and i try to make a big FORM for ordering direct from this.
frist i read out the group+category+product(id, name) than i have the for ... so this was simple. but now if i send to the card i get only one product in the cart becaus all from have the same hidden name. :
PHP Code:
session_start();
if (!empty($_POST['numprod'])) {
$numprod=$_POST['numprod'];
}
if (!empty($_POST['pname'])) {
$prodid=$_POST['$pname'];
}
if (!empty($_POST['basketid'])) {
$basketid=$_POST['basketid'];
}
if (!empty($_GET['op'])) {
$op=$_GET['op'];
}
if(!isset($_SESSION['cart3']))
{
$_SESSION['cart3'] = array();
}
<form method="POST" action="index.php?page=cart&action=add">
<?
$sql_k = "SELECT ID, NAME FROM shopgroup ORDER BY ID ASC";
$result_k = mysql_query($sql_k) or die(mysql_error());
while ($record_k = mysql_fetch_array($result_k)) // list group
{
echo "<div class=\"na\"> $record_k[NAME] </div>";
$sql_pk = "SELECT * FROM shopcategory WHERE GROUPID = '$record_k[ID]'";
$result_pk = mysql_query($sql_pk) or die(mysql_error());
while ($record_pk = mysql_fetch_array($result_pk)) // list category
{
$sql_p = "SELECT ID, PRODUCTID, PRICE
FROM shopproduct
WHERE CATID = $record_pk[ID]
ORDER BY PRODUCTID ASC";
$result_p = mysql_query($sql_p) or die(mysql_error());
$i = 1;
echo "<table align=\"center\" border=\"0\" width=\"470\" class=\"list\" cellpadding=\"7\">\n";
echo "<caption >$record_pk[DESC]</caption>";
//echo $customerid;
echo "<tr><td>\n";
while ($record_p = mysql_fetch_array($result_p)) // list product
{
//$pname= $record_p[PRODUCTID];
if($i%4==0)
{
//echo "<div class=\"pro\">$record_p[PRODUCTID] <input type=\"text\" name=\"numprod\" size=\"5\" class=\"dug\" value=\"1\" /></div>\n";
echo "<div class=\"pro\">$record_p[PRODUCTID] <input type=\"text\" name=\"numprod\" size=\"5\" class=\"dug\" value=\"1\" /><input type=\"submit\" value=\"ORDER\" name=\"sub\"></div>\n";
echo "<div class=\"del\"> </div>\n";
?><input type="hidden" name="prodid" value="<?php echo $record_p[ID] ?>"> <?
}
else
echo "<div class=\"pro\">$record_p[PRODUCTID] <input type=\"text\" name=\"numprod\" size=\"5\" class=\"dug\" value=\"1\" /><input type=\"submit\" value=\"ORDER\" name=\"sub\"></div>\n";
?><input type="hidden" name="prodid" value="<?php echo $record_p[ID] ?>"> <?
$i++;
}
echo "</td></tr>\n";
echo "</table><br /><br />\n";
}
}
/*
echo "<hr class=\"red\" />
<div style=\"text-align:right\">
</form></div><br />\n";
*/
echo "<hr class=\"red\" />
<div style=\"text-align:right\">
<input type=\"submit\" name=\"sub\" value=\"order all\" class=\"big\" \" />
</form></div><br />\n";
}
?>
than send it to :
PHP Code:
function order_now()
{
if($cart3[$record_p[ID]]!="" AND is_numeric($cart3[$record_p[ID]]))
{
$qty = $cart3[$record_p[ID]];
$productid = $qty*$record_p[PRICE];
}
else
{
$qty = "";
$productid = "";
}
// now lets check if the product we add is new, or we need to update an existing record
// $query = "SELECT `ID` FROM `".$dbtablesprefix."basket` WHERE `CUSTOMERID` = '".$customerid."' AND `PRODUCTID` = '".$prodid."' AND `FEATURES` = '". $productfeatures . "'";
// $sql = mysql_query($query) or die(mysql_error());
//if (mysql_num_rows($sql) == 0) {
//mysql_query ("INSERT INTO `shopbasket` ( `CUSTOMERID` , `PRODUCTID` , `STATUS` , `ORDERID` , `LINEADDDATE` , `QTY` , `FEATURES`) VALUES ( '" . $customerid . "', '" . $prodid . "', 'BASKET', '0' , '" . Date("d-m-Y @ G:i") . "' , '" . $numprod . "', '".$productfeatures. "')") or die(mysql_error());
//echo $qty;
//echo $productid;
//echo "insert ok";
//}
//$sql = mysql_query($query) or die(mysql_error());
header ('location:http://shop/index.php?page=list&action=list&op=ok');
}
normaly is for one product so i have to put it in a array? could someone help me please?
|