-2

whats wrong ?

$query = "select name from tabl ";
if($run = mysqli_query($con,$query)){

  while($row = mysqli_fetch_assoc($run)) {
      echo $row['name'].'<br>';
      echo $row['username'];
  }

values in the name index are shown. i'm getting this error for username here is the database

epascarello
  • 204,599
  • 20
  • 195
  • 236
  • well you are only selecting the name.... – epascarello Apr 09 '17 at 12:47
  • You're not selecting "username" in the database query. – cosmoonot Apr 09 '17 at 20:13
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – Qirel Apr 11 '17 at 14:42

1 Answers1

1

You are selecting only name in your query. Therefore the reason why you only get the name array. in order to get the username, Change your query to

select name,username from tabl
Rotimi
  • 4,783
  • 4
  • 18
  • 27