2

I am trying to display an array with 6 values but i don't know really how to do it. I tried to post the array with num_rows but it doesn't seem to do it. I don't know how to fix it.

<?php<br>
//four variables to connect to the database<br>
$host= "localhost";<br>
$username="root";<br>
$password='';<br>
$database="pd00255_coursework2_com1025";<br>

//create a database connection instance
$mysqli = new mysqli($host, $username, $password, $database);<br>

//if there are any values in the table, display them one at a time.
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;<br>
}<br>
echo $mysqli->host_info . "<br>";<br>

$sql = "SELECT ID, Name ,Role, Responsibilities, Age, Date of birth,     Email FROM person";<br>
$result = $mysqli->query($sql);<br>

if ($result->num_rows > 0) {<br>
// output data of each row<br>
while($row = $result->fetch_assoc()) {<br>
  echo "id: " . $row["ID"]. " - ID: " . $row["Name"]. " " . $row["Role"]. " " . $row["Responsibilities"]. "Responsibilities" . $row["Age"]. "Age" .     $row["Date of birth"]. "Date of birth" . $row["Email"]."Email" "<br>";
        }<br>
    } else {<br>
echo "0 results";<br>
}<br>
$mysqli->close;<br>
?><br>
Sean Lange
  • 33,028
  • 3
  • 25
  • 40
Peter Djon
  • 23
  • 4

1 Answers1

0

Your query has an error, when selecting the column Date of birth, because it has spaces, try:

"SELECT ID, Name, Role, Responsibilities, Age, `Date of birth`, Email FROM person"
Claudio
  • 5,078
  • 1
  • 22
  • 33