[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

PHP - need help with Fatal error: Call to undefined function

I have 2 files that are used on a particular page via an include statement.

cart_totals.php contains the following:
function GetCartId()
      {
            // This function will generate an encrypted string and
            // will set it as a cookie using set_cookie. This will
            // also be used as the cookieId field in the cart table
            
            if(isset($_COOKIE["cartId"]))
            {
                  return $_COOKIE["cartId"];
            }
            else
            {
                  // There is no cookie set. We will set the cookie
                  // and return the value of the users session ID
                  
                  setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
                  return session_id();
            }
      }
.
.
.

cart_functions.php contains the following:
function RemoveItem($PID,$spec) {
            // Uses an SQL delete statement to remove an item from
            // the users cart

            global $conn_data;
            mysql_query("delete from cart where cookieId = '" . GetCartId() . "' and PID = $PID and spec = '$spec'");

      }
.
.
.

I am receiving the following error :
Fatal error: Call to undefined function getcartid() in /home/ourstore/public_html/includes/cart_functions.php on line 46

If I then go and add the function GetCartId() to my cart_functions.php page I receive the following error:
Fatal error: Cannot redeclare getcartid() (previously declared in /home/ourstore/public_html/includes/cart_functions.php:9) in /home/ourstore/public_html/includes/cart_totals.php on line 28

Does anyone know the best way to correct this problem, can I make a function global?
0
sabecs
Asked:
sabecs
1 Solution
 
Roger BaklundCommented:
Functions are global, but you can not define the same function twice. When you added it to cart_functions.php you should remove it from cart_totals.php. As an alternative, you could keep it in cart_totals.php, but include this file before you include cart_functions.php, so that the function is defined before you use it.
0
 
sabecsAuthor Commented:
Thanks..
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now