calling to a database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
billabon0202
Forum Newbie
Posts: 8
Joined: Wed Feb 20, 2008 11:31 am

calling to a database

Post by billabon0202 »

I am new to using php and mysql. For some reason or another query keeps failing. Could somone help me out with my logic. The query is as follows:

Separate connect file

<?php # mysql_connect.php

DEFINE('DB_USER', '*******');

DEFINE('DB_PASSWORD', '********');

DEFINE('DB_HOST', '**********');

DEFINE('DB_NAME', '********');

$dbc=@mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)

OR die('Could not connect to MYSQL: ' . mysqli_connect_error());

?>

Code within the webpage

<?php
require_once('mysql_connect.php');

$qry= "SELECT DISTINCT (restaurant_info.food_type)
FROM restaurant_info
INNER JOIN restaurants
ON restaurants.rest_id= restaurant_info.rest_id
WHERE restaurants.delivery = 'yes'
ORDER BY food_type ASC";

$result = mysql_query($qry);

if (!$result) {die("Query Failed.");
}else{
while($row = mysql_fetch_array($result)) {
echo '<p>' . $row['food_type'] . '</p>';
}
}
?>

I don't get an error however it says "Query Failed" every time so i am assuming $results isnt pulling information. However when i run the (
SELECT DISTINCT (restaurant_info.food_type)
FROM restaurant_info
INNER JOIN restaurants
ON restaurants.rest_id= restaurant_info.rest_id
WHERE restaurants.delivery = 'yes'
ORDER BY food_type ASC;
)
query in mysql it pulls the info I need.
Thanks for your help
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Re: calling to a database

Post by liljester »

change:

Code: Select all

if (!$result) {die("Query Failed.");
to:

Code: Select all

if (!$result) {die( mysql_error() );
that should tell you why the query is failing.
Post Reply