Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2003
    Posts
    6

    Unanswered: Submit rejection if spot is taken

    Basically I have an ASP page that marks a certain spot where an item is. When the user wants to enter a new item, I want it so that if he tries to take up that same spot (There are many spots) while another item still maintains that spot, there is server side scripted language stating that either the spot is taken try again, or that the spot was free and the data submitted into the database. I've tried various techniques out and none of have worked for me so far.


    The data for the spot in the submit pages is labeled as "Spot". Any help is appreciated.

  2. #2
    Join Date
    Feb 2002
    Location
    North Wales, UK
    Posts
    114
    Can you be a bit more specific to what a "spot" is? Such as what data is actually submitted? How it corresponds to the records in the database?

    A simply way of storing in the script the status of say 20 "spots" is to use an array.
    J^ - web | email
    newsASP Developer

  3. #3
    Join Date
    Jun 2003
    Posts
    6
    I have a form with different fields of data to input. One of these fields has certain values it can be (I put a drop box here), but there can be no duplicate value in that table at the same time. Basically what I want to do is check for a duplicate record in the database through the server scripting. If there is no duplicate record, I want to insert the new data in the database. If there is a duplicate record, I want to make the user go back and pick a value for that field (which I called spot) that isn't already taken. Sorry about any confusion.

  4. #4
    Join Date
    Feb 2002
    Location
    North Wales, UK
    Posts
    114
    Grab all the used values from the table and store them in an array. When the user submits the form your code should loop through the array values checking if the value selected by the user has already been used before.

    If it finds a match then it knows to redirect the user back to the form and inform them that the option they selected has already been used.
    J^ - web | email
    newsASP Developer

  5. #5
    Join Date
    Jul 2003
    Location
    SoCal
    Posts
    721
    Or you could do a select statement:

    Code:
    sSQL = "SELECT COUNT(ID) AS TotalIDs FROM myTable WHERE spot = '" & Trim(Request.Form("spot")) & "'"
    
    'Execute code into recordset "objRS"
    
    If objRS("TotalIDs") > 0 Then
        'Do error code saying the spot is taken
    Else
        'Do an INSERT statement to take that spot
    End If
    "ID" is the column name you want to count (usually a unique ID column). "myTable" is the table that contains your rows of spots. "spot" is the column you're comparing with the input from the form. "objRS" is a recordset that gets populated with the total from the SELECT statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •