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
https://forums.phpfreaks.com/topic/44625-help-setting-up-beginner-php-script/
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>

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?

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.