Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 26th, 2004, 05:10 PM
Authorized User
 
Join Date: May 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to make a sql that having 2 where !?

Hi

I have this code:

Set objRS = Server.CreateObject("ADODB.Recordset")
strSQL = "Select * From nameslist where PersonName = '" & Request.form("A") & "'"
objRS.Open strSQL, objConn, 1, 3

If Not (objRS.BOF Or objRS.EOF) Then
Response.Redirect "tilmeld.asp?error=The name is in USE/make another !"
End If


I want it to work as now, but I want it to say that "if Request.Form("A") is int the DB it should make theerror tilmeld.asp?error=The name....
(IT WORKS)
But how can i make something with
where PersonIP = '" & Request.ServerVariables("REMOTE_ADDR") & "'" So i can get it 2 make a new error
Response.Redirect "tilmeld.asp?error=U have make one name with this IP !"

also i want it 2 check if the Request.ServerVariables("REMOTE_ADDR") is ind the DB then error else/elsenot if the Request.form("A") is in the DB, and if is is then error else

objRS.AddNew
objRS("PersonName") = AA
objRS("PersonIP") = Request.ServerVariables("REMOTE_ADDR")
objRS.Update

hope U understand me !!

 
Old May 26th, 2004, 05:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Assuming that "nameslist" table stores the REMOTE SERVER IP too in it, and as you have given "SELECT * FROM", it is enough that you do check for IP match as given below.

'sometext - specifies the comments for what you got to do there.

CODE
-----

Set objRS = Server.CreateObject("ADODB.Recordset")
strSQL = "Select * From nameslist where PersonName = '" & Request.form("A") & "'"
objRS.Open strSQL, objConn, 1, 3

If Not objRS.EOF Then 'This name has already made a connection
    ' Now checking for the IP match
    If objRS("PersonIP")=Request.ServerVariables("REMOTE_ ADDR") then
        'Code for IP match ERROR
    End If
Else 'No connection made with this name and from this IP.
     'So add the details to the table.
    objRS.AddNew
    objRS("PersonName") = AA
    objRS("PersonIP") = Request.ServerVariables("REMOTE_ADDR")
    objRS.Update
End If

Hope that helps.
Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old May 26th, 2004, 07:00 PM
Authorized User
 
Join Date: May 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes but what if an user with the ip 212.212.212.212 and with the name HANSEN is add to the db and another user with the ip 212.212.52.212 also will add the name HANSEN then it will do it.

And thats is not OK if a name allready is in the db it can't be add again by another user.

and an user that have add a name with an ip can't add another name using the same ip.

thats how i want it to work hope u understand !!

 
Old May 26th, 2004, 07:04 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

On the page you INSERT on try this:

Run this query: "SELECT * FROM yourtable WHERE ip='" & Request.Form("A") & "' OR name='" & Request.Form("B") & "'"

If the query returns nothing, run the INSERT query. Otherwise display an error.

I apologize, I don't know ASP or ASP.NET so maybe Vijay or someone else can translate this to ASP?

HTH,

Snib

<><
 
Old May 26th, 2004, 07:07 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

That is what it does. Please go through that again with the comment I have added there. you would understand what it does.

Code:
Set objRS = Server.CreateObject("ADODB.Recordset")
strSQL = "Select * From nameslist where PersonName = '" & Request.form("A") & "'"
objRS.Open strSQL, objConn, 1, 3
This recordset will be having one records when the user details with name HANSEN from IP 212.212.212.212 already in DB

If Not objRS.EOF Then 'This name has already made a connection
    ' Now checking for the IP match
    If objRS("PersonIP")=Request.ServerVariables("REMOTE_ ADDR") then
        'Code for IP match ERROR
    End If
Else 'No connection made with this name and from this IP.
     'So add the details to the table.
    objRS.AddNew
    objRS("PersonName") = AA
    objRS("PersonIP") = Request.ServerVariables("REMOTE_ADDR")
    objRS.Update
End If

_________________________
-Vijay G
Strive for Perfection
 
Old May 26th, 2004, 07:08 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Sorry Vijay, I guess I should hang out where I know what I'm doing

Snib

<><
 
Old May 26th, 2004, 07:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hey Snib,

Please dont feel bad about that. Nothing was meant for you in my previous post. Actually, I was composing a mail for Want2Learn, by then you had mailed your reply, that made it all in mesh creating a scene that I have replied to what you have mailed on that.

Please do not mistake me. After seeing your reply I was really feeling sorry for that, I should have addressed the name there.

Sorry about that.:)

Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old May 26th, 2004, 07:20 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Hey Vijay, no offense taken. I also should have read your code better. Besides, I really don't have much of a clue what's going on, I'm just going by stuff I read on the internet.

Thanks,

Snib

<><
 
Old May 26th, 2004, 07:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks Snib :)

_________________________
-Vijay G
Strive for Perfection
 
Old May 27th, 2004, 04:48 AM
Authorized User
 
Join Date: May 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay HAPPYGV

U mean like this:

Set objRS = Server.CreateObject("ADODB.Recordset")
strSQL = "Select * From nameslist where PersonName = '" & Request.form("A") & "'"
objRS.Open strSQL, objConn, 1, 3

If Not objRS.BOF Then
Response.Redirect "tilmeld.asp?error=Navnet er desværre optaget/Tilmeldt, og du må vælge et andet !"

   If objRS("PersonIP")=Request.ServerVariables("REMOTE_ ADDR") Then
   Response.Redirect "tilmeld.asp?error=Der er allerede tilmeldt et navn fra denne IP, brug en anden PC for at tilmeld et andet !"
   End If
Else

objRS.AddNew
objRS("PersonName") = AA
objRS("PersonIP") = Request.ServerVariables("REMOTE_ADDR")
objRS.Update

End If






Similar Threads
Thread Thread Starter Forum Replies Last Post
Webpage with DB conection make SQL OVERFLOW rtr1900 Classic ASP Databases 3 March 28th, 2008 07:30 AM
Make 2 or 1 Muhammad Zeeshan SQL Server 2000 2 August 16th, 2007 01:10 PM
Can someone make this? JonathanRay C# 4 February 16th, 2007 08:57 AM
How can I make that? kalchev ASP.NET 2.0 Professional 0 April 3rd, 2006 07:01 AM
How to make hierarchical data "lay flat" using SQL tinlong SQL Language 1 August 1st, 2003 01:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.