0

I have two files this is the file included:

<?php

if (@mysql_connect("localhost","****", "**************") || @mysql_select_db("a_database")) {
    echo "Connected";
} else {
    die("Not connected.");
}

?>

Then this is the main file:

<?php

require "connect.inc.php";

$query = "SELECT `food`, `calories` FROM `food` ORDER BY `id`";


if ($query_run = mysql_query($query)) {
    echo "Success.";
} else {
    echo "Query Failed.";
}



?>

However when the page loads it says "ConnectedQuery Failed."

Why could this be?

2
Contributors
4
Replies
21
Views
4 Years
Discussion Span
Last Post by cereal
0

Add mysql_error() to your execution:

mysql_query($query) or die(mysql_query())

This will output the error, it should help you to solve the problem.

0

That doesn't seem to be outputting anything?

<?php

require "connect.inc.php";

$query = "SELECT `food`, `calories` FROM `food` ORDER BY `id`";


mysql_query($query) or die(mysql_query($query));

?>
0

Anyway, I'm realizing I wrote a wrong example, sorry, I intended:

mysql_query($query) or die(mysql_error());

bye!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.