I do have a PHP script with run fine on my local sever. When i do upload to the production sever it dose not function correctly.
My local sever uses Apache/2.2.22 (Win32) PHP/5.4.5.
Here is an example of the code.
PHP Code:
<?php
require_once('lib/bookmark_fns.php');
// The shopping cart needs sessions, so start one
session_start();
$itemId = $_GET['itemid'];
// get this book out of database
$items = get_item_details($itemId);
foreach($items as $item)
do_html_header($item['ITEM_NAME']);
check_valid_user();
display_item_details($items);
// set url for "continue button"
$target = "index.php";
if($itemId)
{
$target = "show_cat.php?catid=".$item['CATEGORY_ID'];
}
// if logged in as admin, show edit book links
if(check_admin_user())
{
display_button("edit_item_form.php?itemid=".$itemId, "edit-item", "Edit Item");
display_button("admin.php", "admin-menu", "Admin Menu");
//display_button($target, "continue", "Continue");
}
else
{
display_button("show_cart.php?new=".$itemId, "add-to-cart", "Add ".$item['ITEM_NAME']." To My Shopping Cart");
display_button($target, "continue-shopping", "Continue Shopping");
}
do_html_footer();
?>
Here is the problem, on my local sever I must include the foreach loop to access the array from the Sql query. On the production sever it tells me i do have an wrong foreach construct. Help please. :confused:
01-31-2013, 12:57 PM
NogDog
It would help to see the exact error message(s) you are getting. My guess is that the DB query is not working, and therefore $items is false or null instead of being an array, which is what the first argument to foreach() must be.
02-01-2013, 06:17 AM
nassun
Need help
Thanks $items was null
02-01-2013, 08:40 AM
gvre
You should check, using is_array function, if a variable is an array before passing it to foreach. e.g
PHP Code:
if (is_array($items))
{
foreach($items as $item)
{