Vitalka Posted April 18, 2008 Share Posted April 18, 2008 Hello. I get following weird array values related error messages: Notice: Undefined index: 5 in /.automount/server3/export/home/php701_081a04/public_html/store/check_out.php on line 296 Notice: Undefined index: 36 in /.automount/server3/export/home/php701_081a04/public_html/store/check_out.php on line 296 Notice: Undefined index: 6 in /.automount/server3/export/home/php701_081a04/public_html/store/check_out.php on line 296 $value = 0; 293 $new_stock = 0; 294 $stock_prod = 0; 295 foreach ($item_id as $key => $value){ 296 $id_item = $item_id[$value]; 297 $result = mysql_query("SELECT prod_stock FROM products_t WHERE prod_id='$id_item'") or die(mysql_error()); 298 while ($row = mysql_fetch_array($result)){ 299 $stock_prod = $row['prod_stock']; 300 // $new_stock = $stock_prod - 1; 301 } 302 $new_stock = $stock_prod - 1; 303 $result = mysql_query("UPDATE products_t SET prod_stock='$new_stock' WHERE prod_id='$id_item'") or die(mysql_error()); 304 305 } Those index values are are stored in an array, and when I pull them it gives these error messages. Any one know what's up with that? Thanks. Link to comment https://forums.phpfreaks.com/topic/101637-solved-help-with-an-array/ Share on other sites More sharing options...
AP81 Posted April 18, 2008 Share Posted April 18, 2008 What are you doing with this line???: $id_item = $item_id[$value]; I think you should be using $value, i.e. foreach ($item_id as $key => $value){ $result = mysql_query("SELECT prod_stock FROM products_t WHERE prod_id='$value'") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/101637-solved-help-with-an-array/#findComment-520034 Share on other sites More sharing options...
Vitalka Posted April 18, 2008 Author Share Posted April 18, 2008 Thank you for pointing that out. That was what needed to be done. That was silly of me for not just using that from the start. Link to comment https://forums.phpfreaks.com/topic/101637-solved-help-with-an-array/#findComment-520039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.