Jump to content

constants between


zang8027

Recommended Posts

I got functions.php and addToCart.php.

 

I grab a value being passed and setting it to restID.

 

Then, i pass the value in a function to functions.php and try to set it to a constant. When i try to trace out the value of the constant on addToCart, it says, cannot find constant

 

 

Function.php

<?PHP

//**************Function get shopping cart*********************
function get_shopping_cart($restID)
{


	if (! isset($_SESSION['cart']))
	{
		return new ShoppingCart();
		DEFINE('restIDConst',$restID);
		return 'restIDConst';
	}else{
		return unserialize($_SESSION['cart']);
	}

}?>

 

AddToCart
<?php
require_once '../functions/Functions.php';
$restID = $_REQUEST['restId'];
    	$shopping_cart = get_shopping_cart($restID);


        echo constant('restIDConst');
?>

 

 

isn't the scope global for a constant?

Link to comment
https://forums.phpfreaks.com/topic/143547-constants-between/
Share on other sites

Here is why im trying to do this:

 

later on, im using databases to pull info out of and its using the $restID. In my viewCart.php, there is no variable so the stuff being pulled out is not functioning. I want to say, when the session is created, create a constant.

 

Then, when i go to viewCart.php, the constant is set and the database's are using the contstant to pull info out, thus eliminating the error.

 

Later, i can say.. if($restID != restIDConst) { echo "you can not add items from other restaurants to same cart";}

 

 

 

I am hoping this way will work out

Link to comment
https://forums.phpfreaks.com/topic/143547-constants-between/#findComment-753126
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.