Jump to content

Recommended Posts

I'm getting this error: "Notice: Undefined variable: i in C:\xampp\htdocs\halobattles\index.php on line 298". Not sure why I have this error, because I did define it as you can see here:

<?php

$i++;
		$start_battle_id = "start_battle$i";
		$start_battle = '"#start_battle'.$i.'"';
?>

 

All of this code is in a while loop. Not sure if that really effects anything.

Link to comment
https://forums.phpfreaks.com/topic/244783-undefined-variable-error/
Share on other sites

Where you defined it is not the same variable scope where you are using it.

 

In you need help determining why you are getting the error message, you will need to post all the code on the page that would be needed to duplicate the error.

You need to define $i outside of the loop. (show more code if you need help figuring out where)

 

Consider this:

 

$i++; is the same as $i = $i + 1;

 

In this case, the "$i =" is not evaluated until after the "$i + 1" is evaluated, and at that point, $i has not been defined

 

If you wrote:

 

$a = $b + 1;

 

Your error message is $b is undefined. Yes, "$a = ..." will define $a, but $b is not defined.

 

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.