www.webdeveloper.com
Results 1 to 4 of 4

Thread: Need help

  1. #1
    Join Date
    Jan 2013
    Posts
    2

    Question Need help

    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.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,144
    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.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jan 2013
    Posts
    2

    Thumbs up Need help

    Thanks $items was null

  4. #4
    Join Date
    Apr 2010
    Posts
    88
    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)
        {

        }


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles