Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6002955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:03:07+00:00 2026-05-23T01:03:07+00:00

I have the following PHP script : <?php $all_threads=mysql_query(SELECT * FROM forum_threads WHERE category=$_GET[id]);

  • 0

I have the following PHP script :

 <?php
       $all_threads=mysql_query("SELECT * FROM forum_threads WHERE category=$_GET[id]");

       if($all_threads){ ?>
            //Do something.
     <?php
       }
       else { ?>
            //Do something else
      <?php
       } ?>

The table forum_threads is empty, so the query should return ‘false’ according to the documentation at http://php.net/manual/en/function.mysql-query.php and the ‘else’ block should get executed. However, strangely, the if-block is getting executed. How come?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:03:08+00:00Added an answer on May 23, 2026 at 1:03 am

    It will return a MySQL resource, not FALSE on 0 rows. It will return FALSE on a query error.

    You can check mysql_num_rows() instead. It will be 0 if there were no rows returned.

    You also have a SQL injection vulnerabilities. Escape the GET param with mysql_real_escape_string().

    If you can, just ditch mysql_*() and use PDO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a directory structure like the following; script.php inc/include1.php inc/include2.php objects/object1.php objects/object2.php soap/soap.php
I have to following code: http://www.nomorepasting.com/getpaste.php?pasteid=22987 If PHPSESSID is not already in the table
Hi I'm starting out on php and I have the following script <?php $username
I have the following javascript to embed a flash in my page.tpl.php <script type=text/javascript>
I have a PHP script that selects some data from mysql and throw it
I have a global.php file that I call from the top of every script.
I have the following php code, which has been snipped for brevity. I am
I have the following arrays in PHP (okay they are a bit bigger but
I have the following string in the smarty (php templating system) variable $test: <img
I have the following code: http://www.nomorepasting.com/getpaste.php?pasteid=22615 Which is called by the javascript mentioned in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.