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

  • SEARCH
  • Home
  • 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 772555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:49:13+00:00 2026-05-14T18:49:13+00:00

I have this function to prepare variable to be used in a SQL query:

  • 0

I have this function to prepare variable to be used in a SQL query:

function sqlize($mInput)
{
    if (!isset($mInput))
        $mInput = "null";

    elseif (strtolower($mInput) == "null") { }

    elseif (is_numeric($mInput)) { }

    elseif (is_string($mInput))
    {
        $mInput = trim($mInput);
        $mInput = addslashes($mInput);
        $mInput = '"' . $mInput . '"';
    }
    else
        $mInput = "null";
    return $mInput;
}

I have a string “0004”, which is going in a “varchar field”, is cought by is_numeric, and is saved as “4” and not “0004”. Is there a way to detect the padding and process it as a string?

Thank you!

EDIT

Correct answer based on Cesar and webbiedave tips:

    function sqlize($mInput)
    {
        switch(TRUE)
      {
            default: break;
            case (!isset($mInput)): $mInput = "null"; break;
            case (strtolower($mInput) == "null"): break;
            case (is_numeric($mInput)):
                if ((string) intval($mInput) === (string) $mInput)
                    break;
            case (is_string($mInput)):
                    $mInput = trim($mInput);
                    #v2
                    $mInput = $_SESSION['oCore']->oDatabase->sanatize($mInput);
// ADOdb's oDb->qstr();                 
                    # v1
                    #$mInput = addslashes($mInput);
                    #$mInput = '"' . $mInput . '"';
                    break;
        }
        return $mInput;
}
  • 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-14T18:49:14+00:00Added an answer on May 14, 2026 at 6:49 pm

    instead of is_numeric() use (int)$var == $var
    I saw a beautiful use of the switch, should be something like this:

    function sqlize($mInput)
    {
        switch(TRUE)
        {
            default:
            case (!isset($mInput)): $mInput = "null"; break;
            case (strtolower($mInput) == "null"): break;
            case (is_numeric($mInput)): break;
            case (is_string($mInput)):
                $mInput = trim($mInput);
                $mInput = addslashes($mInput);
                $mInput = '"' . $mInput . '"';
                break;
        }
        return $mInput;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 539k
  • Answers 539k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Maybe this will help you a bit: Unfortunately the current… May 17, 2026 at 2:20 am
  • Editorial Team
    Editorial Team added an answer 1). Hide the table when resizing. 2). Froze layout processing… May 17, 2026 at 2:20 am
  • Editorial Team
    Editorial Team added an answer Never mind, I figured it out. The symbol that indicates… May 17, 2026 at 2:20 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

If I have something like this from the server side, from a fetch: array(1)
I have the following chunk of a header file BKE_mesh.h: /* Connectivity data */
The user comes to this page from a different page where they click on
I've attached onsubmit handler in a form tag like this: <form action=file.php method=post onsubmit=
I have recently decided to switch all my current plain mysql queries performed with
I have a case where I want to use the results of a prepared
Having a reallllll mind pain. I have a php image uploader which is all
I writing real estate web site with basic function for choosing and ordering realty.
Hey guys, I have a bit of a weird problem. I have a jquery
Edit: Prepare my objects for the use within a HashMap. after reading a bit

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.