0

This php line

<?php if($_SESSION['count'] >= 3)?> 

of code gives me the following error message

Notice: Undefined index: count in C:\xampp\htdocs\vb\Step4.php on line 451 Number of Room/s

Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57
Rolls
  • 9
  • 1
  • 5
  • You are confusing with [count](http://php.net/manual/en/function.count.php) function instead of count key – Madhur Bhaiya Sep 15 '18 at 07:31
  • 1
    Possible duplicate of ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – Nigel Ren Sep 15 '18 at 07:44

2 Answers2

0

You need to check for the existence of the count index before trying to use it - so:

<?php
    if( !empty( $_SESSION['count'] ) && intval( $_SESSION['count'] ) >= 3 ){/* do something */}
?>

You could use isset to test that the index has been defined but empty does that and also checks that whatever value is held does is not empty and not equate to false.

Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
0

Session with name 'count' is not set. i.e. The array $_SESSION does not any key with name 'count'.

Also, it is a NOTICE ( information ) not an ERROR.

ViralP
  • 223
  • 2
  • 7
  • so where do I set the 'count' – Rolls Sep 15 '18 at 07:43
  • If you are expecting 'count' in $_SESSION then ideally you should have set 'count' in session using `$_SESSION['count'] = 3;` before calling `if($_SESSION['count'] >= 3)` Please see [PHP Manual](http://php.net/manual/en/session.examples.basic.php) for examples. – ViralP Sep 16 '18 at 06:47