Stuck on PHP/MySQL project

When I try to access items in my database I get a blank screen. No errors…just a blank screen. If anyone wants to take a look at my code I would appreciate it.

[php]

<?php $hostname = "localhost"; $db_user = "root"; $db_password = "mypass"; $database = "myDB"; $db_table = "menu"; $db = mysql_connect($hostname, $db_user, $db_password); if (!$db) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database,$db); $item = $_POST['food']; $query = 'SELECT * FROM menu WHERE Item = "$item"'; $result2 = mysql_query($query); if(!$result2){ echo 'Invalid query: ' . mysql_error() . "\n"; echo 'Whole query: ' . $query; } while($row = mysql_fetch_array($result2,MYSQL_BOTH)); { echo $item . " "; echo $row['price']; echo $row['item']; echo $row[3]; printf($row['price']); } mysql_free_result($result2); ?>

[/php]

your error is probably caused by the semi-colon at the end of the while command (see here)
[php]while($row = mysql_fetch_array($result2,MYSQL_BOTH)); // <-- remove this semi-colon [/php]

also, you might want to swap these quotes around:
[php]$query = ‘SELECT * FROM menu WHERE Item = “$item”’;[/php]
to
[php]$query = “SELECT * FROM menu WHERE Item = ‘$item’”;[/php]

variables in single quotes are not changed to their values,
IE:
[php]$greet = ‘hello’;
echo ‘$greet’; // outputs: $greet
echo “$greet”; // outputs: hello[/php]

Hope that helps,

Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service