-2

I have this code :

if (isset($form['status']) && $form['status'] == 0)
    $status0 = ' selected';
elseif (isset($form['status']) && $form['status'] == 1)
    $status1 = ' selected';

HTML:

<option <?PHP echo $status0; ?>>YES</option>

Now, I see This Error:

PHP Notice:  Undefined variable: status0 in C:\xampp\htdocs\project\cms.php on line 212

How Do i can fix This?!

user27133
  • 487
  • 4
  • 16
  • 31
  • You have to define it first `$status0 =null` at the top – M Khalid Junaid Apr 19 '14 at 15:10
  • It doesn't really matter what value in the MySQL database is. The error indicates that when the variable `$status0` is referenced, it has not yet been defined. (We conclude that the `if` condition did not evaluate to TRUE, and that `$status0` isn't defined anywhere else before line 212. The "fix" is to define the variable somewhere other than just following an `if`. – spencer7593 Apr 19 '14 at 15:23

2 Answers2

3

PHP gave you the answer:

PHP Notice:  Undefined variable: status0 in C:\xampp\htdocs\project\cms.php on line 212

Declare your vars before the if statement: $status0 = null;

toesslab
  • 5,092
  • 8
  • 43
  • 62
2

It seems that $status0 is not defined, because it skips all your if/elseif blocks. You can fix it by assigning $status0 to the default value before the clauses or add else clause and assign $status0 in it.

potashin
  • 44,205
  • 11
  • 83
  • 107