troubleshooting Question

using PHP and MySQL to build a web query

Avatar of chipsterva69
chipsterva69 asked on
PHPMySQL Server
8 Comments3 Solutions473 ViewsLast Modified:
I have been staring at this for far too long to admit, but I am stumped.  I am a newbie to PHP and MySQL but have a relatively good grasp on SQL, so I would like to think I know what I am doing here.  Unfortunately, results prove different.

I have built a simple form to submit information into a very simple MySQL dbase - will expand it later when the client firms up the requirements.  The submission part works.

Now to pull the results.  I can get a simple 'SELECT * FROM table' to work, but when I try to insert a WHERE parameter, I get a syntax error.

Here is the code on the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Dynamic Menu</title>
</head>

<body>

<?
// Make a MySQL Connection
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

// Retrieve all the data from the "example" table
$result = mysql_query("SELECT * FROM test1 WHERE show = '1'")
or die(mysql_error());  

// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry

while($row = mysql_fetch_assoc($result))
{
    echo "Title :{$row['title']} <br>" .
         "Description : {$row['description']} <br>" .
         "Price : {$row['price']} <br><br>";
}

?>



</body>
</html>

Like I said - this works fine until I add the 'WHERE show = '1'.

My thinking is the show field in the dbase table is a bit flag - true or false - that indicates if a particular entry should be visible or not.  I have tried setting the field type to tinyint (1 or 0), varchar (1 or 0), or boolean.  I have tried permutations of 'show is 1', 'show is true', 'show > 0' and 'show = '1' '.

I hate to say how much time I have spent on this one particular piece - it is killing me.  As near as I can tell, the PHP/MYSQL dbase does not have bit value, so should I be using tinyint?  VARCHAR?  What is the syntax to successfully query against it?

Thanks in advance!
ASKER CERTIFIED SOLUTION
jayarjo

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros