The following query is not executing and I am stumped as to why. The query is returning my die clause of ‘error querying database’ yet all of my info is exact.
Have I got a syntax error in my query variable?
<?php
$db_host = 'localhost';
$db_user = 'root';
$db_pass = 'root';
$db_database = 'bbg_db_2';
$dbc = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a database connection');
$query = "SELECT category_name, category_desc FROM categories";
$result = mysqli_query($dbc, $query) or die ('error querying database');
while ($row = mysqli_fetch_array($result)) {
$catname = $row['category_name'];
$catdesc = $row['category_desc'];
echo "<li>$catname</br><span>$catdesc</span></li>";
}
mysqli_close($dbc);
?>
Two problems:
mysqlAPI, but then tried to query with themysqliAPI;mysqli_select_db.Performing some basic error checking with
mysqli_error($dbc)would have revealed this to you pretty quickly.Also, as a style note, ARGH tabs inside lines! Bad! Wrong! Tabs are for indentation, not alignment.