Image

Imagegwynn_aaron wrote in Imagephp

Help with PHP

I'm trying to access a database using the PHP code below the cut tag. There are two places where this should be displaying output in the document. The first is in the title of the page with the <? echo "$brand"; ?> tag. The second is in the body with the <? echo "$brand_display"; ?> tag. In both cases there is simply nothing being displayed.

This is running on my local machine with a MySQL installation I just installed yesterday morning. I also installed phpMyAdmin in order to work with the database and that seems to be working just fine. Using it I created a database and created tables within it.

I think you should be able to view the page in question at this address, but I'm not positive: http://varda.homeunix.net/Sun Gro/Sun Gro/products_displaySunshinepro_mix.php

<?php $section = "products_sunshinepro_mix"; ?>
<?php $name = "products"; ?>
<?php $title = "Products"; ?>
<?php include "_formatting.php"; ?>

<?
// Start session
session_start();
session_register('valid');
$id = $GLOBALS["id"];

// Define variables
$db_host = "********";
$db_user = "********";
$db_pass = "********";
$db_name = "sungroDB";
$table_name = "products";
$connection = @mysql_connect($db_host, $db_user, $db_pass) or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
?>

<?
// Define variables
$sql = "SELECT product_id, product_name, product_brand FROM $table_name WHERE product_brand = '" . $_GET['product_brand'] . "' ORDER BY product_name";
$result = @mysql_query($sql,$connection) or die("Couldn't execute query.");
$brand_display = "<div class=\"side_nav_sub\">";

// Start the while loop
while ($row = mysql_fetch_array($result)) {
$id = $row['product_id'];
$product = $row['product_name'];
$brand = $row['product_brand'];
$brand_display .= "<a class=\"side_nav_sub\" href=\"products_displayProduct.php?id=$id\">$product</a>";
}

$brand_display .= "</div>";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Sun Gro Horticulture | <? echo "$title"; ?> | <? echo "$brand"; ?></title>

<? echo "$incMeta"; ?>

<link rel="Stylesheet" href="style.css" type="text/css" />

<? echo "$incJavascript"; ?>

</head>
<body id="body">
<div align="center">

<? echo "$incHeader"; ?>

<? echo "$incNavigation"; ?>

<? echo "$incBodyStart"; ?>

<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="body_left" width="170" align="left" valign="top">
<div class="side_nav">
<a class="side_nav" href="products_sunshinepro_mix.php">Sunshine Professional Mixes</a>
<? echo "$brand_display"; ?>
<a class="side_nav" href="products_sunshinepro_peat.php">Sunshine Professional Peat Moss</a>
<a class="side_nav" href="products_technigro.php">Technigro Water Soluble Fertilizer</a>
<a class="side_nav" href="products_strong-lite.php">Strong-Lite</a>
<a class="side_nav" href="products_sunshine_bark.php">Sunshine Bark-Based Mixes</a>
<a class="side_nav" href="products_packaging.php">Packaging Specifications</a>
<a class="side_nav" href="products_julian_mix.php">Julian Calendar</a>
</div>
<? echo "$columnSpacer"; ?>
</td>
<td class="body_main" width="100%" align="left" valign="top">
<? echo "<img src=\"images/layout/section_headers/$name.png\" alt=\"$title\" width=\"250\" height=\"41\" border=\"0\" />"; ?>
<p class="head">Sunshine Professional Growing Mixes</p>
<p>Solutions for every grower. Sun Gro Horticulture is leading the way in professionally formulated growing mixes. We have long set the standard for the industry to follow. We formulate our mixes to give consistent results in every bag, bale and truckload. Across North America and around the globe, you will find that Sunshine growing mixes meet the demands of professional growers.</p>
<div align="center"><img src="images/products/pro_mixes.jpg" alt="Sunshine Professional Mixes" width="275" height="226" hspace="0" vspace="10" border="0" /></div>
</td>
<td class="body_right" width="170" align="right" valign="top">
<img style="display: block;" src="images/photos/products_01.jpg" alt="Products" width="150" height="270" border="0" />
<? echo "$columnSpacer"; ?>
</td>
</tr>
</table>

<? echo "$incBodyEnd"; ?>

</div>
</body>
</html>