We help IT Professionals succeed at work.
Get Started

PHP - select - where statement

Ricky Nguyen
Ricky Nguyen asked
Last Modified: 2012-05-11
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"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<title>Test 1</title>
$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); ?>

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,

Watch Question
Top Expert 2004
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE