anarkyandy
Gebruiker
- Lid geworden
- 17 aug 2010
- Berichten
- 14
Halllllllllllooooooooooo ....
Ik heb de volgende vraag.
Ik heb een php functions page en het gaat om een winkelwagen. Het probleem is dat mensen meerdere vaken moeten invoelen voor een product. Now wil ik die vakken tegelijk submitten maar dat lukt dus niet.(alles moet naamelijk in een temp. DB komen...logisch). mijn vraag is ... wat doe ik now fout? pls help mij. ik denk dat het aan de javascript is.
Groeten Andy ...
dit zijn mijn scripts....
HTML/PHP winkelwagen ...
... En de PHP function page is ...
Ik weet dat het een betje veel is maar ik zal op sugesties wachten ...
Alle opmerkingen welkom ... positive feedback ...
Ik heb de volgende vraag.
Ik heb een php functions page en het gaat om een winkelwagen. Het probleem is dat mensen meerdere vaken moeten invoelen voor een product. Now wil ik die vakken tegelijk submitten maar dat lukt dus niet.(alles moet naamelijk in een temp. DB komen...logisch). mijn vraag is ... wat doe ik now fout? pls help mij. ik denk dat het aan de javascript is.
Groeten Andy ...
dit zijn mijn scripts....
HTML/PHP winkelwagen ...
PHP:
<?php
// Include MySQL class
require_once('inc/mysql.class.php');
// Include database connection
require_once('inc/globaltype.inc.php');
// Include functions
require_once('inc/functionstype.inc.php');
// Start the session
session_start();
// Process actions
$cart1 = $_SESSION['cart1'];
$action = $_GET['action'];
switch ($action) {
case 'add':
if ($cart1) {
$cart1 .= ','.$_GET['id'];
}
else {
$cart1 = $_GET['id'];
}
break;
case 'delete':
if ($cart1) {
$items = explode(',',$cart1);
$newcart1 = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newcart1 != '') {
$newcart1 .= ','.$item;
} else {
$newcart1 = $item;
}
}
}
$cart1 = $newcart1;
}
break;
case 'update':
if ($cart1) {
$newcart1 = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'qty')) {
$id = str_replace('qty','',$key);
$items = ($newcart1 != '') ? explode(',',$newcart1) : explode(',',$cart1);
$newcart1 = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart1 != '') {
$newcart1 .= ','.$item;
} else {
$newcart1 = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart1 != '') {
$newcart1 .= ','.$id;
} else {
$newcart1 = $id;
}
}
}
}
}
$cart1 = $newcart1;
break;
case 'update1':
if ($cart1) {
$newcart1 = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'text')) {
$id = str_replace('text','',$key);
$items = ($newcart1 != '') ? explode(',',$newcart1) : explode(',',$cart1);
$newcart1 = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart1 != '') {
$newcart1 .= ','.$item;
} else {
$newcart1 = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart1 != '') {
$newcart1 .= ','.$id;
} else {
$newcart1 = $id;
}
}
}
}
}
$cart1 = $newcart1;
break;
case 'update2':
if ($cart1) {
$newcart1 = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'rev')) {
$id = str_replace('rev','',$key);
$items = ($newcart1 != '') ? explode(',',$newcart1) : explode(',',$cart1);
$newcart1 = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart1 != '') {
$newcart1 .= ','.$item;
} else {
$newcart1 = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart1 != '') {
$newcart1 .= ','.$id;
} else {
$newcart1 = $id;
}
}
}
}
}
$cart1 = $newcart1;
break;
case 'update3':
if ($cart1) {
$newcart1 = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'serie')) {
$id = str_replace('serie','',$key);
$items = ($newcart1 != '') ? explode(',',$newcart1) : explode(',',$cart1);
$newcart1 = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart1 != '') {
$newcart1.= ','.$item;
} else {
$newcart1 = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart1 != '') {
$newcart1 .= ','.$id;
} else {
$newcart1 = $id;
}
}
}
}
}
$cart1 = $newcart1;
break;
}
$_SESSION['cart1'] = $cart1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MultiWerkplaatsHJ</title>
<script language='javascript'>
<!--
function submitform()
{
document.myform.submit();
document.myform1.submit();
document.myform2.submit();
document.myform3.submit();
}
-->
</script>
<?php
echo writeShoppingCart1();
?>
<table width="800px">
<tr>
<td width="50px"> </td>
<td width="100px"><h4>Productnummer<h4></td>
<td width="100px"><h4>Omschrijving<h4></td>
<td width="100px"><h4>Text op Plaat<h4></td>
<td width="80px"><h4>Revisie<h4></td>
<td width="80px"><h4>Serien Nummer<h4></td>
<td width="80px"><h4>Aantal<h4></td>
</table>
<?php
echo showCart1();
?>
<form action="bestellentype.php" method="get">
<input type="submit" id="button1" name="button1" value="Bevestig bestelling!"/>
</form>
<p><a href="Succes.php">Bestel nog een product</a></p>
</div>
</div>
</body>
</html>
... En de PHP function page is ...
PHP:
<?php
function writeShoppingCart1() {
$cart1 = $_SESSION['cart1'];
if (!$cart1) {
return '<p>Er zijn geen producten in de winkelwagen.</p>';
} else {
// Parse the cart1 session variable
$items = explode(',',$cart1);
$s = (count($items) > 1) ? 'en':'';
return '<p><a href="Winkelwagentype.php">'.count($items).' product'.$s.' in de Winkelwagen</a></p>';
}
}
function showCart1() {
global $db;
$cart1 = $_SESSION['cart1'];
if ($cart1) {
$items = explode(',',$cart1);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<table width="800px">';
foreach ($contents as $id=>$qty)
{
$sql = 'SELECT * FROM typeplaatjes WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr>';
$output[] = '<td width="50px"><a href="Winkelwagentype.php?action=delete&id='.$id.'" class="r">Verwijder</a></td>';
$output[] = '<td width="100px">'.$typenr.'</td>';
$output[] = '<td width="100px">'.$omschrijving.'</td>';
$output[] = '<form action="Winkelwagentype.php?action=update1" method="post" id="myform1" name="myform1">';
$output[] = '<td width="100px"><input type="text" name="text'.$id.'" value="'.$text.'" size="12" maxlength="12" /></td>';
$output[] = '</form>';
$output[] = '<form action="Winkelwagentype.php?action=update2" method="post" id="myform2" name="myform2">';
$output[] = '<td width="80px"><input type="text" name="rev'.$id.'" value="'.$rev.'" size="4" maxlength="4" /></td>';
$output[] = '</form>';
$output[] = '<form action="Winkelwagentype.php?action=update3" method="post" id="myform3" name="myform3">';
$output[] = '<td width="80px"><input type="text" name="serie'.$id.'" value="'.$serie.'" size="8" maxlength="8" /></td>';
$output[] = '</form>';
$output[] = '<form action="Winkelwagentype.php?action=update" method="post" id="myform" name="myform">';
$output[] = '<td width="80px"><input type="text" name="qty'.$id.'" value="'.$qty.'" size="8" maxlength="5" /></td>';
$output[] = '</form>';
$total += $prijs * $qty;
$output[] = '</tr>';
}
$output[] = '</table>';
$output[] = '<div align="center"><br/><a href="javascript: submitform()">Vernieuwen</a></div>';
$output[] = '<form action="../Winkelwagentype.php?action=update4" method="post" id="cart1">';
$output[] = '<p><h4>Productieorder Nummer</h4></p><input type="text" name="prodordernr'.$cart1.'" value="'.$prodordernr.'" size="10" maxlength="10" />';
$output[] = '</form>';
}
else {
$output[] = '<p>Winkelwagen is leeg.</p>';
}
return join('',$output);
}
Ik weet dat het een betje veel is maar ik zal op sugesties wachten ...
Alle opmerkingen welkom ... positive feedback ...