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
                  return $_COOKIE["cartId"];
                  // 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?
Who is Participating?
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.
sabecsAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.