I am learning PHP through the New Boston Youtube video tutorials.
When I run the query in the PHP script (script is below error message) on my localhost, I get an error message that is repeated twice. Please error message see below.
I want to be able to run this query within the PHP script and return the information I queried for.
Error message when I run index.php:
Notice: Undefined index: calories in /Applications/XAMPP/xamppfiles/htdocs/Database_To_Server/index.php on line 10
Notice: Undefined index: calories in /Applications/XAMPP/xamppfiles/htdocs/Database_To_Server/index.php on line 10
Code:
index.php
<?php
require 'connect.inc.php';
$query = "SELECT 'food' 'calories' FROM `food` ORDER BY 'id'";
if ($query_run = mysql_query($query)) {
while ($query_row = mysql_fetch_assoc($query_run)) {
$food = $query_row['food'];
$calories = $query_row['calories'];
}
} else {
echo mysql_error();
}
?>
connect.inc.php
<?php
$conn_error = "Could not connect.";
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';
$mysql_db = 'a_database';
if (!@mysql_connect($mysql_host, $mysql_user, $mysql_pass) || !@mysql_select_db($mysql_db)) {
die($conn_error);
}
?>