Script SQL query fails to execute

In the following string, an SQL query for data to the database returns an else condition.

 $sql = $db->select('table', array('special_url' => $_GET['table_name'], 'status' => 1));

Open in new window

This should return data to the index page, however it results in a 404 redirect by script
if ($sql->exists) {
	$name = $sql->fetch();
} else redirect("404.php");

Open in new window

So were getting a 404 even though we have data in the database where the status is equal to 1

some of the variable names have been changed, because of the nature of the data involved.

Any thoughts on what were missing here or a way to discover what is causing the else redirect condition
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Any time you're unsure of what data exists in a variable, you can use var_dump() to print out the contents.  I would start in the first snippet and try this after the statement:


The output from that function is usually easier to read if you use "view source."

Since the second snippet makes a decision based on the properties of the $sql variable set in the first snippet, you will at least be able to see what is in the $sql object.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
freejointventureAuthor Commented:
Thank you ) that is perfect.
freejointventureAuthor Commented:
Excellent answer thank you.
Ray PaseurCommented:
Glad to help -- thanks for the points and thanks for using E-E, ~Ray
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.