lingo5 Posted October 25, 2012 Share Posted October 25, 2012 (edited) hi, I have the PHP code below wher I'm trying to echo the contant CNT_TXT_EMPTYMESSAGE. i have trie everything...with double quotes...single...with nothing...everything but nothing seems to work. Am i using the correct syntax to do this? Many thanks <?php include_once('config.php'); if (!$config['currencyCode']) $config['currencyCode'] = 'EUR'; if (!$config['text']['cartTitle']) $config['text']['cartTitle'] = 'Shopping Cart'; if (!$config['text']['singleItem']) $config['text']['singleItem'] = 'Item'; if (!$config['text']['multipleItems']) $config['text']['multipleItems'] = 'Items'; if (!$config['text']['subtotal']) $config['text']['subtotal'] = 'Subtotal'; if (!$config['text']['update']) $config['text']['update'] = 'update'; if (!$config['text']['checkout']) $config['text']['checkout'] = 'checkout'; if (!$config['text']['checkoutPaypal']) $config['text']['checkoutPaypal'] = 'Checkout with PayPal'; if (!$config['text']['removeLink']) $config['text']['removeLink'] = 'remove'; if (!$config['text']['emptyButton']) $config['text']['emptyButton'] = 'empty'; if (!$config['text']['emptyMessage']) $config['text']['emptyMessage'] = '.CNT_TXT_EMPTYMESSAGE.'; if (!$config['text']['itemAdded']) $config['text']['itemAdded'] = 'Item added!'; if (!$config['text']['priceError']) $config['text']['priceError'] = 'Invalid price format!'; if (!$config['text']['quantityError']) $config['text']['quantityError'] = 'Item quantities must be whole numbers!'; if (!$config['text']['checkoutError']) $config['text']['checkoutError'] = 'Your order could not be processed!'; if ($_GET['ajax'] == 'true') { header('Content-type: application/json; charset=utf-8'); echo json_encode($config); } ?> Edited October 25, 2012 by lingo5 Quote Link to comment https://forums.phpfreaks.com/topic/269912-please-help-echoing-constant/ Share on other sites More sharing options...
jcbones Posted October 25, 2012 Share Posted October 25, 2012 Constants are considered strings when inside of quotes. Correct would be: echo CNT_TXT_EMPTYMESSAGE; Are you sure this constant doesn't contain an empty message? Quote Link to comment https://forums.phpfreaks.com/topic/269912-please-help-echoing-constant/#findComment-1387724 Share on other sites More sharing options...
lingo5 Posted October 25, 2012 Author Share Posted October 25, 2012 No jc, the constant is not empty Quote Link to comment https://forums.phpfreaks.com/topic/269912-please-help-echoing-constant/#findComment-1387725 Share on other sites More sharing options...
jazzman1 Posted October 25, 2012 Share Posted October 25, 2012 No jc, the constant is not empty How did you define it? Could you post the code, please? Quote Link to comment https://forums.phpfreaks.com/topic/269912-please-help-echoing-constant/#findComment-1387727 Share on other sites More sharing options...
lingo5 Posted October 25, 2012 Author Share Posted October 25, 2012 all my constants ae defined on a separate file that i include on each page. This is the code for the constant define ('CNT_TXT_EMPTYMESSAGE',"Your cart is empty"); Quote Link to comment https://forums.phpfreaks.com/topic/269912-please-help-echoing-constant/#findComment-1387728 Share on other sites More sharing options...
Pikachu2000 Posted October 25, 2012 Share Posted October 25, 2012 You don't assign a value to the constant, or echo it in that code. Where have you done that? Quote Link to comment https://forums.phpfreaks.com/topic/269912-please-help-echoing-constant/#findComment-1387729 Share on other sites More sharing options...
jazzman1 Posted October 25, 2012 Share Posted October 25, 2012 (edited) I remember you Why are you using single quotes around it, in the very first post ? PS: It should be, if (!$config['text']['emptyMessage']) $config['text']['emptyMessage'] = CNT_TXT_EMPTYMESSAGE; Edited October 25, 2012 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/269912-please-help-echoing-constant/#findComment-1387731 Share on other sites More sharing options...
PFMaBiSmAd Posted October 25, 2012 Share Posted October 25, 2012 (edited) The correct syntax is - if (!$config['text']['emptyMessage']) $config['text']['emptyMessage'] = CNT_TXT_EMPTYMESSAGE; Edit: seems to be an echo in here.............. Edited October 25, 2012 by PFMaBiSmAd never mind the forum's post notification fails again. Quote Link to comment https://forums.phpfreaks.com/topic/269912-please-help-echoing-constant/#findComment-1387733 Share on other sites More sharing options...
lingo5 Posted October 25, 2012 Author Share Posted October 25, 2012 weird... i was including the php file where all my constants are defined at the top of each page like so: include ('../constants.php'); I have changed this to include ('constants.php'); ..and it works now !!!. How come....my constants.php file is one dir up... Quote Link to comment https://forums.phpfreaks.com/topic/269912-please-help-echoing-constant/#findComment-1387747 Share on other sites More sharing options...
jazzman1 Posted October 25, 2012 Share Posted October 25, 2012 (edited) No, that's no possible! You have to have a constants.php file in the same directory or you are handling a different file or you have more including files. Copy/paste this code to check where are you.. echo dirname(__FILE__); Edited October 25, 2012 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/269912-please-help-echoing-constant/#findComment-1387753 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.