Announcement

Collapse
No announcement yet.

Validate Duplicate Entry

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validate Duplicate Entry

    I have Created a simple Item Master Form my fields are Id,Name and Price , I want to validate duplicate Name , can anyone suggest me how to validate duplicate name which is not accepting and showing error message "Duplicate Item Name" , my Database is mysql and table name Itemmaster,

  • #2
    you have 2 options:

    1.- use and ajax on change event (wouldnt recommend it)
    2.- use the onvalidate event of the form where you check the name and use sc_error to display the error message and avoid the saving of the new item.

    Regards

    Comment


    • #3
      Thanks !

      i am using both option but when i try to edit old items then also shown error message

      my OnValidation Code :

      sc_select(my_data, "select name,id from itemmast");
      $eDuplicate=0;
      if ({my_data} === false)
      {
      echo "Access error. Message =". {my_data_erro};
      }
      else
      {
      while (!$my_data->EOF)
      {
      if ({name}=$my_data->fields[0] ) {
      $eDuplicate=1;

      }

      $my_data->MoveNext();
      }
      $my_data->Close();
      }

      if ($eDuplicate=1 ) {
      sc_error_message("Duplicate Item Name ");
      }


      Regards

      Comment


      • #4
        there is your error man, and to be honest is not optimal. Your query should be something like

        PHP Code:

        $query 
        "SELECT *
                       FROM   itemmast
                       WHERE  itemname = '" 
        . {itemname} . "' AND id <> " . {id}; // in the query you look for the name where the id is different to the current ID =  in case is new the currentID should be = 0

        sc_lookupmy_data$query)

        if ( isset( {
        my_data[0][0]} ) ) // if you found data then you found the name. therefore you display the error.
        {
             
        sc_error("you already captured that item... silly rabbit!!!!!");

        Comment


        • #5
          Thank you very much.

          Comment


          • #6
            but when i update old record show some error

            Error updating database - record not found

            Comment


            • #7
              Thanks kafecadm there some other issue.

              Comment


              • #8
                Well lemme know if I can be of help.

                Regards

                Comment


                • #9
                  why in 'if you use = and not ==

                  Comment

                  Working...
                  X