Link to home
Start Free TrialLog in
Avatar of DDean
DDean

asked on

ip compare DB field loginIP to REMOTEadr

I have a from that a visitor completes. It saves the form in an access db with current date (date format) as dateadded and Request.ServerVariables("REMOTE_ADDR") as loginIP (textfield). There a a couple of field saved but the are not important at this time.
Once the visitor completes the form they can not resubmit another form until the next day. So if a visitor tries to submit a second form on the same day they are sent to a "too bad fo you you have to wait until tomorrow" page.

I query the table  where the dateadded equal date() and loginIP=Request.ServerVariables("REMOTE_ADDR") Right now I can get the new ip from the second attempt to submit another form and I can response.write both the dateadded and the loginIP but when i query it nothing happens. I have looked all over the web for a solution but i can't find a solution or a part solution I can expand on. I ahve attached the code I am having a problem with.newtest.txt
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

I used a simpler page to test this.  I had to change the SQL string to put '#' around the date and single quotes around the IP address text.
SQL = "SELECT * FROM Contestvotes where dateadded = #" & finaldate & "# and LoginIP = '" & NewIP & "'"

Open in new window

Avatar of DDean
DDean

ASKER

Dave,it still isn't selecting base on the where. Could it be possible may structure is wrong

there 3 fields
dateadded - type: date/time short date added as default
selection - type: text length 50
loginIP - Type: text length 15 123.456.789.012 ( the length was 14. fixed ... that still no work

here is the code that I last tried

If I don't select 'where' I can list all the fields including the calculated fields

5/7/20155/10/201564.114.228.241
5/7/20155/10/201564.114.228.241
5/4/20155/10/201564.114.228.241
5/3/20155/10/201564.114.228.241
5/2/20155/10/201564.114.228.241
5/8/20155/10/201564.180.179.174
5/10/20155/10/201564.114.228.241
5/8/20155/10/201564.114.229.185

I am beginning to feel rather stupid. In my mind the code should work
Thoughts???
Avatar of DDean

ASKER

Forgot the code
newtest.txt
Attached is the code I used for testing along with all the sections I commented out.
NewIP.txt
Avatar of DDean

ASKER

it does the 'Response.Write("final date2:  " & finaldate2 & "  this is new IP:  "&NewIP) '

and I was getting tat as well.. but it doesn't do 'SQLstr = "SELECT * FROM Contestvotes where dateadded = #" & finaldate & "# and LoginIP = '" & NewIP & "'" '

nothing happens I get the response write at the top but the compare selection in the do while and the response at the bottom do nothing as if the 'do while' isn't finding anything.
Don't know what to tell you.  It's works exactly as described here.  I would have to add entries for it to find anything for today.  'today' is the date it is comparing it to.  Your code won't find anything else as it is written.
Avatar of DDean

ASKER

date records I have been using:

Table: Contestvotes

dateadded      selection          loginIP
5/8/2015            2                 64.180.179.174
5/10/2015          1                 64.114.228.241
5/10/2015          2                 64.114.229.185

structure:

dateadded      Date/Time
selection         Text(50)
loginIP             Text(15)

It in theory it should only find the second record ... the ip listed is my IP so I should get the 'sorry you can't vote again until tomorrow'

All I want is to prevent someone from adding a second vote until the next day. If there is a better way to do this, I am all ears. To me, my code seemed to be simple logical way to achieve this .. but apparently not  
 : (
It's a weird one. Apparently ASP VBscript is still aware of the 'date' format when you do the comparison.  When I used 'Cstr' to convert it, then it works.  Updated code attached.
NewIP.txt
Avatar of DDean

ASKER

we are half waythere. the 'sorry' displays but when I changed the last day I voted to 5/8/2015 I should get the contest message but is goes to the 'sorry' message.  

I tried changing the sql to
SQLstr = "SELECT * FROM Contestvotes where dateadded < #" & finaldate & "# and LoginIP = '" & NewIP & "'"

And all I got was a blank page ...
That version with '<' is doing a string comparison, not really a date comparison.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DDean

ASKER

I think you did it !!! I will try this in the morning ... my brain is FULL
Avatar of DDean

ASKER

But it looks like it worked !! I truly can't thank you enough!! Happy Happy
Avatar of DDean

ASKER

Like I said ... Happy Happy !!!
A further addition because you want the most recent entry first...
SQLstr = "SELECT * FROM Contestvotes where LoginIP = '" & NewIP & "' ORDER BY dateadded DESC""

Open in new window

You're welcome, glad to help.