InquisitiveProgrammer
asked on
My drop-down menu isn't getting populated
Here is the code:
When looking at it in a browser, I only get an empty drop-down menu.
When looking at it in a browser, I only get an empty drop-down menu.
<?php session_start(); ?>
<HTML>
<HEAD><TITLE>Florida Pet Clinics Inc.</TITLE>
</HEAD>
<BODY>
<H1 ALIGN="CENTER">Florida Pet Clinics Inc. </H1>
<?php>
define("MYSQLUSER", "???");
define("MYSQLPASS", "???");
define("HOSTNAME", "d???");
define("MYSQLDB", "???");
$customer = $_SESSION['curr_customer'];
echo "You are viewing the information for customer number " . $customer . "<br />";
$connection = new mysqli(HOSTNAME, MYSQLUSER, MYSQLPASS, MYSQLDB);
if ($connection->connect_error) {
die('Connect Error: ' . $connection->connect_error);
}
else {
$query = "SELECT PetNumber, PetName FROM Pet WHERE CustomerNumber = $customer";
$result = $connection->query($query);
if ($result->num_rows < 1) {
echo 'No pets have been added for this customer';
}
else {
echo "<select id='pet' name='pet'>";
echo "<option value=' '></option>";
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
echo "<option value='{$row->PetNumber}'>{$row->PetName}</option>";
}
echo "</select>";
}
}
?>
<P><A HREF="addpetinfo.php">Add New Pet</A>
</BODY>
</HTML>
What does the HTML source look like after the page finishes loading?
ASKER
My syntax is wrong for how I'm providing my database row results, but I'm not sure what I'm doing wrong:
<HTML>
<HEAD><TITLE>Florida Pet Clinics Inc.</TITLE>
</HEAD>
<BODY>
<H1 ALIGN="CENTER">Florida Pet Clinics Inc. </H1>
You are viewing the information for customer number 16<br /><select id='pet' name='pet'><option value=''></option><option value=''></option></select>
<P><A HREF="addpetinfo.php">Add New Pet</A>
</BODY>
</HTML>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have this code now:
and I get the following errors:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/35/d387195482/h tdocs/lodw ig/custome rinfo.php on line 50
else {
$query = "SELECT PetNumber, PetName FROM Pet WHERE CustomerNumber = $customer";
$result = $connection->query($query);
if ($result->num_rows < 1) {
echo 'No pets have been added for this customer';
}
else {
echo "<select id='pet' name='pet'>";
while ($row = $result->fetch_array()) {
$rows[]=$row;
}
foreach($rows as $row) {
echo "<option value='$row[\"PetNumber\"]'>'$row[\"PetName\"]'</option>";
}
echo "</select>";
}
}
and I get the following errors:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,