Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP Warning:  Use of undefined constant

Posted on 2004-09-15
8
Medium Priority
?
484 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
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 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

688 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