简体   繁体   中英

Why does “if($_SESSION['count'] >= 3” giving me error?

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

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM