Hi there,
Having difficulties with updating a form which returns a rows with products and textareas. Adding function works perfect.
Where I have troubles is the update function which when clicked updates the textareas but if I am refreshing or leaving the page and come back, the rows are still there but no text in the textareas.
I'm lost, please...
<?php session_start();
$cart2 = $_SESSION['cart2'];
$action = $_GET['action'];
switch ($action) {
case 'add':
if ($cart2) {
$cart2 .= ','.$_GET['id'];
} else {
$cart2 = $_GET['id'];
}
break;
case 'update':
if ($cart2) {
$specifics = $_POST['specifics'];
$items = explode(',',$cart2);
$newcart = '';
foreach ($_POST as $key=>$value) {
if (stristr($key, 'specifics')) {
$id = str_replace('specifics', $key);
$item = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart2);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$id;
} else {
$newcart = $id;
}
}
}
}
}
$cart2 = $newcart;
break;
}
$_SESSION['cart2'] = $cart2;
?>
The page:
function showCart2() {
$cart2 = $_SESSION['cart2'];
//foreach ($items as $item) {
//$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
//}
$output[] = '<form action="dragon-schedule.php?action=update" method="post" id="cart2">';
$output[] = '<table width="950" cellpadding="0" cellspacing="0" id="dragon_schedule_data">';
$output[] = '<tr>';
//$output[] = '<td align="center" width="54">Quantity</td>';
$output[] = '<td align="center" width="104">Neck Size<br />
mm</td>';
$output[] = '<td align="center" width="100">Product Code</td>';
$output[] = '<td align="center" width="300">Description</td>';
$output[] = '<td align="center" width="100">Image</td>';
$output[] = '<td align="center" width="100">Comments</td>';
//$output[] = '<td align="center" width="200" class="noprint">Remove from Schedule</td>';
$output[] = '<td align="center" width="120"><input type="submit" value="Update Schedule" class="noprint" /></td>';
$output[] = '</tr>';
if ($cart2) {
$items = explode(',',$cart2);
$contents = array();
foreach ($items as $id) {
$query = "(SELECT schedule, id, id_dco_ls, description, neck_size, prod_code, img, notes FROM dco_ls WHERE id_dco_ls = $id) UNION
(SELECT schedule, id, id_dco_ps, description, neck_size, prod_code, img, notes FROM dco_ps WHERE id_dco_ps = $id)";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result); {
extract($row);
$output[] = '<tr>';
$output[] = '<td align="center" width="100">'.$neck_size.'</td>';
$output[] = '<td align="center" width="100">'.$prod_code.'</td>';
$output[] = '<td align="center" width="300">'.$description.'</td>';
$output[] = '<td align="center" width="100">'.$img.'</td>';
$output[] = '<td align="center" width="100"><textarea name="specifics[]" cols="35" rows="5">'.$specifics.'</textarea></td>';
$output[] = '</tr>';
}}
$output[] = '</table>';
$output[] = '</form>';
} else {
$output[] = '<p>Your project schedule is empty.</p>';
}
return join('',$output);
}
?>
[edited by: jatar_k at 2:18 pm (utc) on Mar 4, 2010]
[edit reason] fixed font size [/edit]