-2

Have the following PHP:

<?php
session_start();
$conn = mysqli_connect("localhost", "test", "", "test");

if (mysqli_connect_errno()) {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql = "SELECT status FROM updates";
if ($result = mysqli_query($conn, $sql)) {
    while ($row = mysqli_fetch_row($result)) {
        echo '<div class="statusRow">' . "Status: " . $row['status'] . '</div>';
    }
    mysqli_free_result($result);
}
mysqli_close($conn);
?>

The above is not returning the desired 'status' input, just blank. Not sure what I am missing here?

mickmackusa
  • 43,625
  • 12
  • 83
  • 136
Michael Philibin
  • 373
  • 1
  • 2
  • 16

2 Answers2

2

The problem is you using mysqli_fetch_row, it returns numeric array. You need to switch to mysqli_fetch_assoc. Then you will be able to access via string $row['status']

http://php.net/manual/en/mysqli-result.fetch-assoc.php

0

Change $row['status'] to $row[0] or use mysqli_fetch_assoc()

Kevin P
  • 601
  • 3
  • 9