Check also whether it is not empty:
if(is_array($_SESSION['cart']) and !empty($_SESSION['cart']))
or check for elements one level below:
if(is_array($_SESSION['cart'][$i]) and !empty($_SESSION['cart'][$i]))
or check for elements two levels below:
if(isset($_SESSION['cart'][$i]['productid'])) {
$pid=$_SESSION['cart'][$i]['productid'];
} else {
echo 'No product ID!';
}
broj1
Nearly a Posting Virtuoso
1,212 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
whawhat's the code on line 61? show the code block before this line too.
diafol
Keep Smiling
10,672 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
Your test should be within a loop where $i is defined:
for($i=0;$i<$max;$i++)
Otherwise you can not test for $_SESSION['cart'][$i]
broj1
Nearly a Posting Virtuoso
1,212 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
why use js for hidden field. just use multiple submit buttons with unique name attributes
diafol
Keep Smiling
10,672 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
Can you post the contents of the $_SESSION['cart'] before updating? Put this code between lines 12 and 13:
die(print_r($_SESSION['cart'], 1));
broj1
Nearly a Posting Virtuoso
1,212 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
OK, but as I stated in my previous post please send the contents of the $_SESSION before the for loop (see above). Even better if you send the contents of the $_SESSION both before and after the foor loop so we can compare. Use the following code:
else if(isset($_REQUEST['command'])=='update'){
// this will display the contents of the $_SESSION['cart'] before the update
print_r($_SESSION['cart']);
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=(isset($_SESSION['cart'][$i]['productid']));
$q=intval($_REQUEST['product'.$pid]);
if($q>0 && $q<=999){
$_SESSION['cart'][$i]['qty'] = $q;
}
// this will display the contents of the $_SESSION['cart'] after the update
// and end the script
die(print_r($_SESSION['cart'], 1));
else{
$msg='Some proudcts not updated!, quantity must be a number between 1 and 999';
}
}
broj1
Nearly a Posting Virtuoso
1,212 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13
RE: help on multiple submits...
<form ...>
...other form fields...
<input type="submit" name="insert" value="Update" />
<input type="submit" name="delete" value="Delete" />
<input type="submit" name="order" value="Order" />
</form>
This form sent to a formhandler page, then the action is determined by the submit button used:
if($_POST){
switch(true){
case isset($_POST['insert']):
//do whatever
break;
case isset($_POST['update']):
//do whatever
break;
case isset($_POST['order']):
//do whatever
break;
default:
//error
break;
}
}
Or something like that.
diafol
Keep Smiling
10,672 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57