I'm trying to get data from an database that I have created in phpMyAdmin. My problem is that however I change my query I'm getting the same type of error message using the mysql_error()
function:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''foods'' at line 1
PHP code index file:
<?php
require 'connect.inc.php';
$query = "SELECT 'food_type', 'calories' FROM 'foods'";
if($query_run = mysql_query($query)){
while ($query_row = mysql_fetch_assoc($query_run)){
$food = $query_row('food_type');
$calories = $query_row('calories');
echo $food.' has '.$calories.' calories ';
}
}else{
echo mysql_error();
}
?>
PHP code database connection file:
<?php
$connectionError = 'Can\'t connect.';
$mySqlHost = 'localhost';
$mySqlUser = 'root';
$mySqlPassword = 'Bhu8Nji9';
$mySqlDataBase = 'my_first_database';
if(!@mysql_connect($mySqlHost, $mySqlUser, $mySqlPassword) || !@mysql_select_db($mySqlDataBase)){
die($connectionError);
}else{
//echo 'Connected';
}
?>