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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:02:42+00:00 2026-05-23T23:02:42+00:00

What is a proper way to filter parameters passed in functions? The goal is

  • 0

What is a proper way to filter parameters passed in functions? The goal is to make the function secure, especially when working with a database.

Example:

function user_profile($user_id)
{
   //get user's profile data
   $query = "SELECT * FROM `users` WHERE `user_id` = $user_id";
}

$user_id is a URI segment.

Other general examples are welcomed.

  • 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-23T23:02:42+00:00Added an answer on May 23, 2026 at 11:02 pm

    To escape strings, use the same method you’d use outside the function:

    $user_id= mysql_real_escape_string($user_id);
    

    If you’re expecting the value to be, for example, an integer and would like to return error from the function if it isn’t, you can do something like:

    if (!is_int($user_id)) {
      return FALSE;
    }
    else // do you query
    

    Or if you expect it to match some specific pattern, do so with preg_match():

    // For example, $user_id should be 4 letters and 4 numbers
    if (!preg_match("/^[A-Z]{4}[0-9]{4}$/", $user_id)) {
       return FALSE;
    }
    else // do you query
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could somebody recommend to me the proper way of writing filter functions for ajax
What is the proper way to indicate something like an example given a list
I would like to clarify what is the proper way to filter user input
What's the proper way to initialize a class_attribute in Rails? I am using this:
What is the most proper way to sending email of minimal 1000 or more
What's the proper way to convert from a scientific notation string such as 1.234567E-06
What is the proper way to minimize a WinForms app to the system tray?
What's proper way to connect ODBC datasources and execute some SQL statements? TQuery and
What is the proper way to terminate a Swing application from the code, and
what's the best/proper way of interacting between several windows in C# app? Recently, I've

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.