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 422763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:06:49+00:00 2026-05-12T19:06:49+00:00

I use query string to access my pages. I try to make if anyone

  • 0

I use query string to access my pages. I try to make if anyone type unknown query string manually, then redirect to somewhere..

For example:

Url: test.php?m=1 (this is a valid url)
test.php?m=1324234 (this is not a valid url )
test.php?m=1asdaa (this is not a valid url )

include("config/database.inc");
$qm=$_GET['m'];
 $query = "select acc from test where acc=$qm"; 
 $numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);
  if ($numrows == 0){
          header("Location: index.php"); 
          exit;
     }

In the database i have two line, LINE 1: acc=1; LINE 2: acc=2;

If i type to the url: test.php?m=12312431, then redirect to index.php ‘coz $numrows=0. Thats ok.
But if i type: test.php?m=1sdfsfsf, then i got this error msg.:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in..

How can i do that? Need to check the $_GET[‘m’] before query from database?

Thank you.

  • 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-12T19:06:49+00:00Added an answer on May 12, 2026 at 7:06 pm

    You should never be placing the value of a GET variable directly into an SQL query without properly filtering and escaping it. Your problem is that you’re allowing things which aren’t numbers to be put into your SQL query. In this particular case, your test is harmless and just errors, but a malicious user could also do things much more harmful via SQL injection.

    Instead, what you really want to do is convert the variable’s value to a type that you know is okay (in this case, an integer) and then query the database using that. Try this instead:

    include("config/database.inc");
    $qm=intval($_GET['m']);
     $query = "select acc from test where acc=$qm"; 
     $numresults=mysql_query($query);
     $numrows=mysql_num_rows($numresults);
      if ($numrows == 0){
              header("Location: index.php"); 
              exit;
         }
    

    Notice the call to intval() which forces the result to be an integer value, instead of potentially harmful strings.

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

Sidebar

Related Questions

No related questions found

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.