Jump to content

[SOLVED] Undefined Index Error?


limitphp

Recommended Posts

Notice: Undefined index: loginMode in C:\wamp\www\inc_login_script.php on line 2

 

I'm not sure what is wrong here.

In the index.php file I have an include:

include("inc_login_script.php");

 

In the inc_login_script.php on line 2 is this:

$loginMode = $_POST['loginMode'];

 

I just installed wamp server 5.2.9-2

Is there another setting I need to turn on? 

 

Link to comment
Share on other sites

Nope. You need to check if the index 'loginMode' exists in $_POST array, before you try to assign its value to anything.

 

if(isset($_POST['loginMode'])) {
  $loginMode = $_POST['loginMode'];
}

 

 

Or you can just disable reporting of E_NOTICE level error messages.

Link to comment
Share on other sites

Is this a new error?

I don't remember getting all these errors, several months ago when I had wamp server installed?

Your previous installation most probably had a setting called display_errors disabled or the error_reporting level was set to ignore notices. Notices are not errors, these do not prevent your script from running however they are simple to correct.

Link to comment
Share on other sites

Its actually giving me another :

Notice: Undefined variable: s in C:\wamp\www\inc_login_script.php on line 5

 

on line 5 I have this:

$salt = "®$s:<š1ašskj67^&&*&*";

 

It thinks I'm declaring s because there is a $ sign in front of it. 

Can you not have a dollar sign as part of a value in a variable?

 

 

 

Link to comment
Share on other sites

That's because default error levels have changed in WampServer's recent version.

 

Notices are not serious errors . They're rather indicating parts of your code, that might lead to unexpected behaviour.

 

As I said, you can just disable these messages (look in php.ini for error_reporting). This will make your script work, but is not a recommended thing to do. The proper line of action is to correct your code, so that no notices are thrown.

 

[edit]

 

See? The actual value of $salt was not ®$s:<š1ašskj67^&&*&* but ®:<š1ašskj67^&&*&*

Link to comment
Share on other sites

Change the double quoes to single quotes.

 

That actually got rid of that one....thanks...

 

"As I said, you can just disable these messages (look in php.ini for error_reporting). This will make your script work, but is not a recommended thing to do. The proper line of action is to correct your code, so that no notices are thrown."

 

Thats what I'd like to do, but I have so many dang notices, its going to take me a while to fix them all....

 

Notice: Undefined index: loginMode in C:\wamp\www\inc_login_script.php on line 2

 

Notice: Undefined index: logout in C:\wamp\www\inc_login_script.php on line 3

 

Notice: Undefined index: time in C:\wamp\www\index.php on line 10

 

Notice: Undefined index: genre in C:\wamp\www\index.php on line 33

 

Notice: Undefined index: genres in C:\wamp\www\index.php on line 44

 

Notice: Undefined variable: genres in C:\wamp\www\index.php on line 54

 

Notice: Undefined index: currentpage in C:\wamp\www\index.php on line 172

 

Notice: Undefined variable: audioplayer_soundfiles in C:\wamp\www\inc_vote_view.php on line 31

 

Notice: Undefined variable: audioplayer_artists in C:\wamp\www\inc_vote_view.php on line 32

 

Notice: Undefined variable: audioplayer_titles in C:\wamp\www\inc_vote_view.php on line 33

 

Notice: Undefined variable: loginFailureMessage in C:\wamp\www\index.php on line 410

 

Are you supposed to declare variables before you use them?

 

 

 

Link to comment
Share on other sites

$integer = 0;
$float = 0.0;
$string = '';
$array = array();

 

You can of course use other initial values if needed

 

 

What about this example:

 

//**********************************	HANDLE TIME	******************
if($_GET['time'])	//*****Get Existing time Value
{ 
$time = $_GET['time']; 
}
elseif($_SESSION['time'])
{
  $time = $_SESSION['time'];   
}
//Validate
$time = ceil($time);
if(empty($time) || !is_numeric($time) || $time < 1 || $time>365)
{
  $time = 60;  
}
//Set Session variable for next time
$_SESSION['time'] = $time;
//*************************************************************************

 

If time doesn't exist, I want to do something....

I'm thinking, I don't understand another basic principle of coding....

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.