Announcement

Collapse
No announcement yet.

how to prevent entering same value on the same day?

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

  • how to prevent entering same value on the same day?

    hi guys, i have simple form single record, there is a value that i want to prevent users to add it duplicated on the same day, (type: integer) i have also the date field in the same table fields like {dateofentry} this is to prevent adding a record for the same issue on the same day...but they can add it next day is fine

    any hint? using SC8


    Mike

  • #2
    onValidate

    sc_lookup(rs,"SELECT COUNT(issue) FROM your_table WHERE issue = {issue} AND dateofentry = {dateofentry}"); //depending on your needs, you could also use CURDATE()
    if(isset({rs[0][0]}) && {rs[0][0]} > 0)
    {
    sc_error_message("Already recorded!");
    sc_error_exit();
    }

    jsb

    Comment


    • #3
      YOU ARE THE MAN jsb, like always, a real live saver

      appreciated dude

      Comment


      • #4
        its a nice post ...........
        ***~~~Faizan Hashmi~~~***

        Comment


        • #5
          jsb, i tried that it is adding the record normally! maybe i am missing something
          my key field which shouldn't be repeated in the same date is {stno}, and the date field is {dateofentry}, so i put this on validate:


          Code:
          sc_lookup(rs,"SELECT COUNT(stno), FROM daily_act WHERE stno = {stno} AND dateofentry = {dateofentry}");
          if(isset({rs[0][0]}) && {rs[0][0]} > 0)
          {
          sc_error_message("This student is already registered for this day!");
          sc_error_exit();
          }
          then opened this single-record form and added new record that has stno already registered for the same dateofentry, it normally added it, tried again, and could add it many times in the same day


          what could be going wrong

          Comment


          • #6
            Why don't you just put quotes around your date field. '{dateofentry}' :-)

            Oh, and btw I suggest to put all in the BeforeInsert event.

            jsb

            Comment


            • #7
              Oh, jsb, you didn't only save a life here, you answered an old question that why date field sometimes jpeople put a quote, even SC internally adds that in the code... i tried to google it long time ago to know more about it but useless, then forgot it loool

              anyway, problem was extra coma after the
              Code:
              sc_lookup(rs,"SELECT COUNT(stno),
              when removed the coma, worked as supposed to, i have nothing in the beforeInsert of this form... only the copy of last day data that you gave me earlier it is in OnScriptInt


              Appreciated boss

              Mike

              Comment

              Working...
              X