Hey guys

I am getting an error in my php coding, Undefined variable .

When I click on a category on the index.php, I get the error

Notice: Undefined variable: HTTP_GET_VARS in C:\wamp\www\chapter25\show_cat.php on line 6

This is the code for show_cat.php

<?php
  include ('book_sc_fns.php');
  // The shopping cart needs sessions, so start one
  session_start();

  $catid = $HTTP_GET_VARS['catid'];
  $name = get_category_name($catid);

  do_html_header($name);

  // get the book info out from db
  $book_array = get_books($catid);

  display_books($book_array);


  // if logged in as admin, show add, delete book links
  if(isset($HTTP_SESSION_VARS['admin_user']))
  {
    display_button('index.php', 'continue', 'Continue Shopping');
    display_button('admin.php', 'admin-menu', 'Admin Menu');
    display_button("edit_category_form.php?catid=$catid", 
     'edit-category', 'Edit Category');
  }
  else
    display_button('index.php', 'continue-shopping', 'Continue Shopping');

  do_html_footer();
?>

Any ideas why im getting this error?

Thanks

    define $HTTP_GET_VARS['catid'] and your undefined catid variable error will be solved.

    ..probably should use $_GET instead of $HTTP_GET_VARS, no one uses it.

    if the var isn't define until later in the script, use something like

    $catid = (isset($GET['catid'])) ? $GET['catid'] : null;

    to define $catid when $_GET['catid'] isn't present in the url query.

      Thanks Coldwerturkey, that worked 🙂

      Now got another problem. After that category has been displayed, You can click on the items for more of a detail description for the products. Im getting this error now.

      Notice: Undefined variable: HTTP_GET_VARS in C:\wamp\www\chapter25\show_book.php on line 6

      <?php
        include ('book_sc_fns.php');
        // The shopping cart needs sessions, so start one
        session_start();
      
        $isbn = (isset($_GET['isbn'])) ? $_GET['isbn'] : null;
      
        // get this book out of database
        $book = get_book_details($isbn);
        do_html_header($book['title']);
        display_book_details($book);
      
        // set url for "continue button"
        $target = 'index.php';
        if($book['catid'])
        {
          $target = 'show_cat.php?catid='.$book['catid'];
        }
        // if logged in as admin, show edit book links
        if( check_admin_user() )
        {
          display_button("edit_book_form.php?isbn=$isbn", 'edit-item', 'Edit Item');
          display_button('admin.php', 'admin-menu', 'Admin Menu');
          display_button($target, 'continue', 'Continue');
        }
        else
        {
          display_button("show_cart.php?new=$isbn", 'add-to-cart', 'Add '
                         .$book['title'].' To My Shopping Cart'); 
          display_button($target, 'continue-shopping', 'Continue Shopping');
        }
      
        do_html_footer();
      ?>
      
      

        this:

        Notice: Undefined variable: HTTP_GET_VARS in C:\wamp\www\chapter25\show_book.php on line 6

        should never ever happen if the problem line 6 looks like this:

        $isbn = (isset($_GET['isbn'])) ? $_GET['isbn'] : null;

        I'm at a loss. Are you sure you refreshed the page, and it's the right page?

          Yeh I have refreshed the page and its the correct page. I'm new to PHP so im finding this language hard to grasp :queasy:

            Write a Reply...