how to find if the query was successful

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Leena P
    New Member
    • Mar 2007
    • 11

    how to find if the query was successful

    I have a insert query which is fired when the form is submitted sometimes users enters illegal characters or for some reason query is not executed properly
    how to find if the query has run successfully or not
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Very bad practice. Always cleanse form data BEFORE inserting into a database.
    By cleanse I mean protect from SQL injection and validate the data.
    As for checking if queries work, php query execution functions do return error codes.
    And there are rows affected functions.
    I cannot be more helpful because you omitted your DB engine

    Comment

    • carmarri
      New Member
      • Dec 2009
      • 5

      #3
      It's true, you should ensure that the data is correct before launch the query, otherwise you can have even security problems on your Database system.

      Anyway you can check a response:

      Code:
      $result = mysql_query("SELECT....",$db);
      if ($result===false)
      {
       echo "error!"
      } else {
       //actions....
      }
      Regards,


      -------------------------------------
      xatcom.net, diseƱo web
      Last edited by Dormilich; Dec 16 '09, 06:39 AM. Reason: Please use [code] tags when posting code

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        ~carmarri, the OP stated that they were using an INSERT query. INSERT and UPDATE queries do not create result resources, as they have no results.

        Comment

        Working...