html - Echo isn't working within a section of my PHP -


okay, trying display text when goes wrong. want have if page number high (above 3 in case) display error. disregard accessing mysql database.

<?php     function get($name)     {         return isset($_request[$name]) ? $_request[$name] : '';     }      function is_valid_index($index,$array)     {         return $index >= 0 && $index < count($array);      } ?>     <?php      //variables  $dbhost = "localhost"; $dbuser = "admin"; $dbpass = "pass"; $dberror = "you have failed connect database!";  $conn = mysqli_connect($dbhost,$dbuser,$dbpass) or die ($dberror);  $select_db = mysqli_select_db($conn, "database") or die ("couldn't select database"); ?>  <form> <?php         $page = array('select list','users', 'groups');          echo '<select name="lists">';             for($i = 0;             $i < count($page);             $i++)             {                 echo '<option value="'.($i + 1).'">'.$page[$i].'</option>';             }         echo '</select>'; ?>     <input type='submit'>     </form> <?php     if(get('page'))     {             $page_id = get('page');             if(is_valid_index($page_id-1,$page))             {                 echo "you have selected".$page[$page_id-1];             }             else             {                 echo '<span style="color:red">invalid page</span>';             }     } ?> 

got tutorial video: https://www.youtube.com/watch?v=sarh2hauixy

change

echo '<select name="lists">';     

into this

echo '<select name="page">'; 

this way function get('page') return true , if block execute , echo calls


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -