Solved

PHP Warning:  Use of undefined constant

Posted on 2004-09-15
8
458 Views
Last Modified: 2008-02-01
How to avoid Warning logs for an undeclared variables in PHP?

I have used many variables as,

$_SESSION[dbConnectInfo][host] = "localhost";
$_SESSION[dbConnectInfo][username] = "root";
$_SESSION[sitePD] = $ROOT_PATH;

and so on.

Errors are as follows,
`````````````````
[Wed Sep 15 04:42:23 2004] [error] PHP Warning:  Use of undefined constant dbConnectInfo - assumed 'dbConnectInfo' in /../../../php/master.php on line 17

How to avoid these error logs. PLease give solutions for this to avoid. But I do not want to supress warning logs.
0
Comment
Question by:isas_n
  • 4
  • 2
8 Comments
 
LVL 32

Expert Comment

by:ldbkutty
ID: 12065269
>> PHP Warning:  Use of undefined constant dbConnectInfo - assumed 'dbConnectInfo'

The error is here: $_SESSION[dbConnectInfo][host]

dbConnectInfo and host not variables because there is no $ symbol. They are not strings because there is no ' or " enclosed.

It should be "host" and "dbConnectInfo".

But, why do you want to store the host and username in SESSION? Are you trying to keep it in session and use it in the required pages. If so, SESSION is not really the best way. Just do the DB Connection in a PHP and include it in the required pages.
0
 
LVL 32

Expert Comment

by:ldbkutty
ID: 12065316
even then, why 2-D for sessions !? this should be enough:

$_SESSION["dbConnectInfo_host"] = "localhost";
$_SESSION["dbConnectInfo_username"] = "root";
$_SESSION["sitePD"] = $ROOT_PATH;
0
 

Author Comment

by:isas_n
ID: 12071732
Hi, ldbkutty

I'm trying to make changes in the code. I will let you know after some time.
`````````````````````````````````````````````````
For example,

$_SESSION[webImgPath] = $_SESSION[siteURL]."/userdata/uploadedimages";

In Most of the pages we are using, the variable,
$_SESSION[webImgPath].

So we can store it in a session, so that it will be used wherever required.

Also we are using only sessions in our program,
eg. Storing field values. That field value will be used in different forms.

Is there any alternate way for this?

0
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!

 
LVL 32

Expert Comment

by:ldbkutty
ID: 12077749
>> Also we are using only sessions in our program, eg. Storing field values
>> Is there any alternate way for this?

If you just want to pass the form-fields to the next page, POST method is enough to retrieve in the next page.
POST carries the field values to the next page, SESSIONS carry all over the pages.

>> $_SESSION[webImgPath]

This is not the right format for SESSIONS. you should have it as: $_SESSION['webImgPath'] or $_SESSION["webImgPath"].

With $_SESSION[webImgPath], If your warnings are suppressed in your php.ini(which is not secure), you wont get any warnings in your output page. Otherwise it will show errors like you got.

So the right format is:

$_SESSION["webImgPath"] = $_SESSION["siteURL"]."/userdata/uploadedimages";

I hope you understand.
0
 
LVL 32

Accepted Solution

by:
ldbkutty earned 500 total points
ID: 12077777
wherever you have $_SESSION[someVar], change it to $_SESSION["someVar"].

One more suggestion. There a re a lot of PHP Experts who dont really look in this 'Programming' section. If you post your Question here, you will get fast and best responses:
http://www.experts-exchange.com/Web/Web_Languages/PHP/
0
 

Author Comment

by:isas_n
ID: 13652072
hello
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
This code tracks birthdays 3 87
Auto-indent certain lines in Notepad++ 10 141
Advice on Xojo as a development tool over VB. 4 81
Generate Unique ID in VB.NET 21 99
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question