Jump to content

Help setting up beginner php script


craiggerz

Recommended Posts

Hi guys, I'm new to php and I'm trying to set up a form that you can select a "filter" and the results will show up. The problem is that nothing is showing up. I've attached it below if someone could tell me what's going wrong that would be great, I'm trying to use a book as a guideline.

 

Thanks!

 

[attachment deleted by admin]

Link to comment
Share on other sites

Sorry lets try this again. I even tried setting $breedName within the PHP file so it's not the HTML file that is calling it that is the problem, there must be something wrong with this code.

 

Thanks again!

 

<!DOCTYPE HTML PUBLIC
                 "-//W3C//DTD HTML 4.01 Transitional//EN"
                 "http://www.w3.org/TR/html401/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <title></title>
</head>

<body>
<?php

	require db.php;

	// Show all dogs with the breedname in a <table>
	function displayDogsList($connection, $query, $breedName) {
		// Run the query on the server
		if (!($result = @ mysql_query ($query, $connection)))
			showerror();

		// Find out how many rows are available
		$rowsFound = @ mysql_num_rows($result);

		// If the query has results ...
		if ($rowsFound > 0) {
		// ... print out a header
			print "Dogs of $breedName<br>";

			// and start a <table>.
			print "\n<table>\n<tr>" .
			"\n\t<th>Wine ID</th>" .
			"\n\t<th>Wine Name</th>" .
			"\n\t<th>Year</th>" .
			"\n\t<th>Winery</th>" .
			"\n\t<th>Description</th>\n</tr>";

			// Fetch each of the query rows
			while ($row = @ mysql_fetch_array($result)) {
				// Print one row of results
				print "\n<tr>\n\t<td>{$row["dog_id"]}</td>" .
				"\n\t<td>{$row["name"]}</td>" .
				"\n\t<td>{$row["price"]}</td>\n</tr>";
			} // end while loop body

			// Finish the <table>
			print "\n</table>";
		} // end if $rowsFound body

		// Report how many rows were found
		print "{$rowsFound} records found matching your criteria<br>";
	} // end of function


	// Connect to the MySQL server
	if (!($connection = @ mysql_connect($hostName, $username, $password)))
		die("Could not connect");

	// Secure the user parameter $regionName
	$breedName = mysqlclean($_GET, "breedName", 30, $connection);

	if (!mysql_select_db($databaseName, $connection))
		showerror();


	//$breedName = "Schnoodle";

	// Start a query ...
	$query = "SELECT * FROM dog";

	// run the query and show the results
	displayDogsList($connection, $query, $breedName);
?>
</body>
</html>

Link to comment
Share on other sites

print "\n<tr>\n\t<td>{$row["dog_id"]}</td>" .
"\n\t<td>{$row["name"]}</td>" .
"\n\t<td>{$row["price"]}</td>\n</tr>";

 

Change to:

 

print "\n<tr>\n\t<td>$row["dog_id"]</td>" .
"\n\t<td>$row['name']</td>" .
"\n\t<td>$row['price']</td>\n</tr>";

 

See if that works...

 

Also view the source of your page in your browser, what is being printed?

Link to comment
Share on other sites

That doesn't seem to work.

 

All that is showing up for my page source is the following, which is obviously not correct.

 

<!DOCTYPE HTML PUBLIC
                 "-//W3C//DTD HTML 4.01 Transitional//EN"
                 "http://www.w3.org/TR/html401/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <title></title>
</head>

<body>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.