0

Hi there,

My script doesn't work properly. I have a function called showCart2 which populate a table with rows and a textareas. Every item has it's own textarea. Users should be able to enter text and submit. Entered text should be hold in the array.

The output of textareas and product items works BUT the update process seems to have some problems. It just won't update.

Any help would be appreciated!!

function showCart2() {
	$cart2 = $_SESSION['cart2'];
		$specifics = $_POST['specifics'];
		$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="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="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[] = '<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'.$id.'" 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);
} 


//Here is the update procedure:

$cart2 = $_SESSION['cart2'];
$action = $_GET['action'];
switch ($action) {
	case 'add':
		if ($cart2) {
			$cart2 .= ','.$_GET['id'];
		} else {
			$cart2 = $_GET['id'];
		}
		break;
	case 'update':
		if ($cart2) {
		$newcart = '';
		foreach ($_POST as $key=>$value) {
			if (stristr($key, 'specifics')) {
				$id = str_replace($specifics, $key);
				$items = ($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;
?>

Edited by pixeldiver: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by EvolutionFallen
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.