Query String
In this ASP tutorial, I'm going to show you how to handle parameters passed from a Query String.
'CORRECT WAY - Parameterized Query with dynamic sql
'--------------------------------------------------
strSQL = "SELECT * FROM users WHERE username=? AND password=?"
Dim cmd1
Set cmd1 = Server.CreateObject("ADODB.Command")
cmd1.ActiveConnection = cnnLogin
cmd1.CommandText = strSQL
cmd1.CommandType = adCmdText
cmd1.Parameters(0) = Request.Form("login")
cmd1.Parameters(1) = Request.Form("password")
Set rstLogin = cmd1.Execute()
Copy
'BAD WAY WITH CONCATENTATION DON'T DO IT!!!
'------------------------------------------
strSQL = "SELECT * FROM users WHERE username='" & Request.Form("login") & _
"' AND password='" & Request.Form("password") & "';"
Set rstLogin = cnnLogin.Execute(strSQL)
Copy
What if you want a LIKE clause in your Query?
SELECT * FROM tblX WHERE Field LIKE '%' & Name & '%'
Copy
Tried this but it didn't work.
SELECT * FROM tblX WHERE Field LIKE '%?%'
Copy
Include ADOVBS.inc in your page to use the Constants.
'Set parameter = command.CreateParameter (Name, Type, Direction, Size, Value)
'cmd1.Parameters.Append(cmd1.CreateParameter("Name", 200, 1, 512, name))
cmd1.Parameters.Append(cmd1.CreateParameter("Name", 200, 1, 512, "%" & name & "%"))
Copy
Or you could wrap it before you assign:
cmd1.Parameters(0) = name
Copy
cmd1.Parameters(0) = "%" & name & "%"
Copy
Pre-Requisite
Members
No members extras today
Recommended Courses
Details
In this tutorial, you will learn how to create a function called FancyText that takes a string and makes one character in that string black for aesthetic reasons. I will then demonstrate how I used Bard from Google and ChatGPT to create a function that darkens the color slightly instead of making it black. You will see that ChatGPT's function worked better, and I will walk you through the code. This tutorial is for VBScript and classic ASP.
Keywords
#asp, #classicasp, #help, #howto, #tutorial, #learn, #lesson, #training, #webdesign, #VBScript, classic ASP, function creation, FancyText, string manipulation, character colorization, Bard from Google, ChatGPT, color adjustment, course page design
Legacy