Link to home
Start Free TrialLog in
Avatar of Ricky Nguyen
Ricky NguyenFlag for Australia

asked on

PHP - select - where statement

HI experts,

I'm having troubles getting my code to select a specific piece of information.

Here is my code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test 1</title>
</head>
<?php
$con = mysql_connect("localhost","warehouse21","tld3");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("warehouse", $con);

$result = mysql_query("SELECT * FROM product 
WHERE productCode='HT400DVA'");

while($row = mysql_fetch_array($result))
  {
  <?php echo $row['productCode'];?>
  <?php echo $row['name'];?>
  <?php echo $row['price'];?>
 "<br />";
  }
?> 
<?php }
mysql_close($conn); ?>
</table></body></html>

Open in new window


I'm trying to get my code to display the following.

Product Code  |  Name   |   Price
HT400DVA         Bike           $50

Thanks in advance,

Rick
Avatar of Francisco Igor
Francisco Igor
Flag of Canada image

Do you want a structured table or simple lines?
First, you are trying to put some php tags within another php code...

//the title line
echo "Product Code  |  Name   |   Price";
echo "<br />";

//the data lines
while($row = mysql_fetch_array($result))
  {
echo $row['productCode'];
echo "|";
echo $row['name'];
echo "|";
echo $row['price'];
echo  "<br />";
  }
you code seams ok, what error do you get?
ASKER CERTIFIED SOLUTION
Avatar of Zyloch
Zyloch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ricky Nguyen

ASKER

Thanks for the fast replies!

@Zyloch

I tried your code and its brought me one step closer I'm getting the following error:

PHP Notice: Undefined variable: conn on line 35 PHP Warning: mysql_close() expects parameter 1 to be resource, null given on line 35

The product code, name and price are showing up now, but that error shows up with them.
You have $conn instead of $con in your mysql_close. Don't give me points for this.
Thanks for the help and Thanks for the correction :)