0

I have a database and a table in it which is looking like this

ID Picture Description.

In my PHP-Code I try to get the "Picture" which is just a text right now and the Description. But I always get

Undefined Index: Description
Undefined Index: Picture

Here my Code:

   <?php include ("db.php"); 

 $conn = new mysqli($servername, $username, $password, $db);

 if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
 } 

$sql = "SELECT Picture, Description FROM family WHERE ID = 1 ";
$result = $conn->query($sql)
or die ("MySQL-Error: " . $conn->error); 

 if ($result->num_rows >0) {
while ($row = mysqli_fetch_row($result)){ 


echo "Pic: " . $row["Picture"]. " - Description: " . $row["Description"]. " 

}
}

 else {
echo "Not good";
}
$conn->close();
echo "Connected successfully"; ?>  

What does the error mean

EDIT: I solved it changed mysqli_fetch_row to mysqli_fetch_assoc

Qirel
  • 25,449
  • 7
  • 45
  • 62
D. Hara
  • 11
  • 1

2 Answers2

0

mysqli_fetch_row returns an enumerated array starting at 0, not an associative array. See: http://php.net/manual/en/mysqli-result.fetch-row.php

Rusty Fausak
  • 7,355
  • 1
  • 27
  • 38
0

Here's the issue:

while ($row = mysqli_fetch_row($result))

you should use mysqli_fetch_array() or mysqli_fetch_assoc()

FelixSFD
  • 6,052
  • 10
  • 43
  • 117
Farsay
  • 312
  • 1
  • 9