Check before insert in Database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steph

    #1

    Check before insert in Database

    hello everyone,

    I would to know how to check the value I am getting from an HTML form.

    Let's put it that way, I need to get a string and I would like to make sure
    this is a string and not a number for instance.

    What kind of test could I use to check that?

    //here is the line where I get the value

    $variable = $_POST['value'];

    The point is I have to insert the data in an Oracle database. And I would
    like to test it before sending the data to the database.

    Any advice, please?


  • Paul Lautman

    #2
    Re: Check before insert in Database

    Steph wrote:[color=blue]
    > hello everyone,
    >
    > I would to know how to check the value I am getting from an HTML form.
    >
    > Let's put it that way, I need to get a string and I would like to
    > make sure this is a string and not a number for instance.
    >
    > What kind of test could I use to check that?
    >
    > //here is the line where I get the value
    >
    > $variable = $_POST['value'];
    >
    > The point is I have to insert the data in an Oracle database. And I
    > would like to test it before sending the data to the database.
    >
    > Any advice, please?[/color]

    How are you defining a string and a number? Is 9,999 a number or a string?


    Comment

    • Gordon Burditt

      #3
      Re: Check before insert in Database

      >I would to know how to check the value I am getting from an HTML form.[color=blue]
      >
      >Let's put it that way, I need to get a string and I would like to make sure
      >this is a string and not a number for instance.[/color]

      Everything you get from $_POST is a string. It might also be the
      string representation of a number.

      Make checks appropriate for the specific data involved. PHP has
      all sorts of nice string functions to pick strings apart, to do
      regular expression matching, etc. If a serial number is supposed
      to be a letter followed by 5 digits, you might match it against
      "[A-Za-z][0-9][0-9][0-9][0-9][0-9]".

      is_numeric() checks for a string that could be interpreted as a number.
      It allows signs, decimal points, and exponential notation.
      [color=blue]
      >What kind of test could I use to check that?
      >
      >//here is the line where I get the value
      >
      >$variable = $_POST['value'];
      >
      >The point is I have to insert the data in an Oracle database. And I would
      >like to test it before sending the data to the database.[/color]

      That's a very good idea, but I don't see what kind of field has restrictions
      like "any string that isn't a number".

      Gordon L. Burditt

      Comment

      • mattyfroese@gmail.com

        #4
        Re: Check before insert in Database

        try is_numeric()

        Finds whether a variable is a number or a numeric string


        I believe 9,999 will return true aswell

        Comment

        • NC

          #5
          Re: Check before insert in Database

          Steph wrote:[color=blue]
          >
          > I would to know how to check the value I am getting from an HTML form.
          >
          > Let's put it that way, I need to get a string and I would like to make sure
          > this is a string and not a number for instance.
          >
          > What kind of test could I use to check that?[/color]

          No test necessary. If you received it via HTTP, it is a string.

          Cheers,
          NC

          Comment

          • Chirag Shukla

            #6
            Re: Check before insert in Database


            Steph wrote:[color=blue]
            > hello everyone,
            >
            > I would to know how to check the value I am getting from an HTML form.
            >
            > Let's put it that way, I need to get a string and I would like to make sure
            > this is a string and not a number for instance.
            >
            > What kind of test could I use to check that?[/color]

            is_numeric function is what we should use to first check if the
            incoming values are valid or not. If not valid, display error message
            or else proceed to check the next variable.

            Comment

            Working...