This is my first post in this community. I am a new to PHP and MySQL. Here is the code that I am trying to run.
I'm using MAMP. I have tested that I am able to establish connection to the "pet" database. Checked my user name and password, that's correct too. I have data in the database with "horse" in the field "petType".
There is got to be something wrong in the code below. I have scratched my head and looked in books and online, but couldn't figure out what I am doing wrong? With the code below, my webpage comes blank.
I'm trying to display records from the database as the first part and worry about formatting later.
<?php
$host = 'localhost';
$username = ' ';
$password = ' ';
$database = 'pet';
$conn = mysqli_connect($host, $username, $password, $database);
$query= "SELECT * FROM pet WHERE petType = 'horse'";
while($row = mysqli_fetch_array($query)):
{
$petDescription = $query [$petDescription];
$petName = $query [$petName];
$petType = $query [$petType];
echo "$petType <br> <br> $petName <br> $petDescription";
}
?>