undefined variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

undefined variables

Post by irealms »

Hi any idea what server settings could cause php variables to show errors like this?

Code: Select all

Notice: Undefined variable: userid in /usr/home/sgerbitz/public_html/beta/index.php on line 6

Notice: Undefined variable: log in /usr/home/sgerbitz/public_html/beta/index.php on line 42

Notice: Undefined index: valid_user in /usr/home/sgerbitz/public_html/beta/i-auth.php on line 4
You are not logged in.
They are set in the format $_SESSION['variable'] or $variable. It doesn't do this on my server only on one a user has set up.
User avatar
angrytuna
Forum Newbie
Posts: 12
Joined: Mon Feb 23, 2004 1:01 am

Post by angrytuna »

The "undefined variable" notices are indicators that you're using (surprise surprise) a variable that you haven't defined yet. The "undefined index" means you're indexing into an array with a key that you haven't defined yet. These are one of three types of error reporting that PHP can do. You'll have to change the error reporting level if you don't care that the variables are not instantiated, but you want the messages to disappear.
See http://us2.php.net/error_reporting
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you should not simply change the error reporting to not show it. Better yet, fix the problem, it is telling you the notice for a reason


for example

Code: Select all

<?php

if (isset($_POST['var']))
{

$_SESSION['var'] = $_POST['var'];

}

?>
Post Reply