0

A PHP Error was encountered Severity: Notice

Message: Undefined variable: role

Filename: views/sample_list.php

Line Number: 9

 <?php if($role[0]['sample']==1){?><a href="<?php echo site_url();?>/welcome/save_sample"><button class="btn btn-add  waves-effect waves-light" type="button">Add Sample</button></a><?php }?>
M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
Juna Thomas
  • 7
  • 1
  • 5
  • 1
    So what's your question? The message is pretty clear. You're using an undefined variable. It simply doesn't exist in that scope. – M. Eriksson Dec 18 '19 at 12:03
  • check from the controller u passed `$role` or not and in view also chek with `isset($role[0]['sample'])` – Devsi Odedra Dec 18 '19 at 12:03
  • update question with `$role` array details – Abhishek Sharma Dec 18 '19 at 12:03
  • @AbhishekSharma - Considering the error message saying that the variable `$role` is undefined, how would they then be able to show us details about it? – M. Eriksson Dec 18 '19 at 12:06
  • then check if variable is set or not as `if( isset($role[0]['sample']) && $role[0]['sample']==1)` – Abhishek Sharma Dec 18 '19 at 12:12
  • Does this answer your question? ["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) – Aksen P Dec 18 '19 at 12:19

1 Answers1

0

place checking with the condition

<?php if((!empty($role[0]['sample']))&&($role[0]['sample']==1)){?><a href="<?php echo site_url();?>/welcome/save_sample"><button class="btn btn-add  waves-effect waves-light" type="button">Add Sample</button></a><?php }?>