Solved

PHP Warning:  Use of undefined constant

Posted on 2004-09-15
8
409 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
endX challenge 2 50
countPairs challenge 7 58
PHP question(s) about order of output 9 42
index Out OF Range Exception error 4 29
RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
A short article about problems I had with the new location API and permissions in Marshmallow
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now