Solved

My drop-down menu isn't getting populated

Posted on 2012-04-03
4
233 Views
Last Modified: 2012-04-03
Here is the code:

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>

Open in new window

0
Comment
Question by:InquisitiveProgrammer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 37802764
What does the HTML source look like after the page finishes loading?
0
 
LVL 1

Author Comment

by:InquisitiveProgrammer
ID: 37802790
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>

Open in new window

0
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 37802816
Try changing:

$row->PetNumber

to:

$row["PetNumber"]
0
 
LVL 1

Author Comment

by:InquisitiveProgrammer
ID: 37802870
I have this code now:

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>";
	}
}

Open in new window


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/htdocs/lodwig/customerinfo.php on line 50
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question