| Author |
Topic |
|
Eagle_f90
Constraint Violating Yak Guru
424 Posts |
Posted - 2002-11-22 : 21:21:09
|
| I am trying to write a select statment to pull information from a database depending on what a user inputed in a form. I know it can be done I just can't fugre out how. What the use does is puts in his name into the form and then the select need to do a select * from database where (the name he gave on the form) = (the name in one the coulmn labled clientname).--For thouse with wings, fly to your dreams. |
|
|
harshal_in
Aged Yak Warrior
633 Posts |
Posted - 2002-11-23 : 00:47:24
|
quote: I am trying to write a select statment to pull information from a database depending on what a user inputed in a form. I know it can be done I just can't fugre out how. What the use does is puts in his name into the form and then the select need to do a select * from database where (the name he gave on the form) = (the name in one the coulmn labled clientname).--For thouse with wings, fly to your dreams.
do u want to fetch the info from the single table or multiple tables? |
 |
|
|
Eagle_f90
Constraint Violating Yak Guru
424 Posts |
Posted - 2002-11-23 : 00:50:28
|
| The info is in a single table.--For thouse with wings, fly to your dreams. |
 |
|
|
harshal_in
Aged Yak Warrior
633 Posts |
Posted - 2002-11-23 : 00:55:38
|
quote: The info is in a single table.--For thouse with wings, fly to your dreams.
it would be like:select * from table_name where client_name =@client_namewhere @client_name is the variable which u should replace by the clientname which u trap in the formharshal. |
 |
|
|
Eagle_f90
Constraint Violating Yak Guru
424 Posts |
Posted - 2002-11-23 : 01:01:00
|
| so would I just do this:dim name@name = request("name")select * from table_name where name = @name--For thouse with wings, fly to your dreams. |
 |
|
|
Eagle_f90
Constraint Violating Yak Guru
424 Posts |
Posted - 2002-11-23 : 02:11:27
|
| That is not wokring, I just keep geting errors.I am using: select * from table_name where uid = formuid"and I get the error invalid coulmn name "formuid"--For thouse with wings, fly to your dreams. |
 |
|
|
harshal_in
Aged Yak Warrior
633 Posts |
Posted - 2002-11-23 : 02:19:37
|
quote: That is not wokring, I just keep geting errors.I am using: select * from table_name where uid = formuid"and I get the error invalid coulmn name "formuid"--For thouse with wings, fly to your dreams.
i GUESS U CAN NOT USE THE FORMUID HERE IT SHOULD BE SOME VARIABLE WHICH U SHOULD BE REPLACING WITH IN THE CODE AND THE QUERY WHICH WILL BE PASSED TO SQL SERVER SHOULD LOOK SOME THING LIKE THIS:SELECT * FROM TABLE_NAME WHERE UID=@VARIABLEAFTER REPLACING THE @VARIABLE IT SHOULD BESELECT * FROM TABLE_NAME WHERE UID='USER_NAME'THIS SHOULD WORK.HARSHAL. |
 |
|
|
Eagle_f90
Constraint Violating Yak Guru
424 Posts |
Posted - 2002-11-23 : 02:59:51
|
| formuid is the varable. above it I have thhis code:dim formuidformuid = request("uid")and I can't do the select * from table_name where uid = 'username' cause the usernames are differant for each person.But affter some messing around I did figure out this is what I had to do:slect * from table_name where uid='" & fouruid & "'"--For thouse with wings, fly to your dreams. |
 |
|
|
ConfusedOfLife
Starting Member
35 Posts |
Posted - 2002-11-23 : 04:27:26
|
| what language are you using? ASP, PHP or what? you're trying to get it from a form, so, you're not working with sql directly as I got! You have to find the structure of the language that you're scripting in. |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2002-11-23 : 12:16:44
|
| Looks like asp to me.You need to use ADO and a replace function.Private Function Replace(strSource As String, strSearch As String,strReplace As String) Dim intPos As Long intPos = InStr(strSource, strSearch) Do While intPos > 0 Mid(strSource, intPos, Len(strSearch)) = strReplace intPos = InStr(strSource, strSearch) Loop Replace = strSourceEnd FunctionDim strClientNamestrClientName = Request("ClientName") strClientName = Replace(strClientName,"'","''")/* This is the simple case if you want you can then modify this to use a command object and call a stored procedure */ Dim objConn, objRS, strSQL, strConnectString strSQL = "SELECT * FROM Clients WHERE clientName = '" & strClientName & "'" strConnectString = "your connection string here" Set objConn = Server.CreateObject("ADODB.Connection") objConn.Open strConnectString Set objRS = Server.CreateObject("ADODB.Recordset") objRS.Open strSQL, objConn '' You can do whatever you want with the recordset here 'Clean up... objRS.Close Set objRS = Nothing objConn.Close Set objConn = Nothing |
 |
|
|
Eagle_f90
Constraint Violating Yak Guru
424 Posts |
Posted - 2002-11-23 : 17:24:19
|
| I have no idea why yours was so hard all I had to do was this:select * from table_name where uid = '" & request("formuid") & "'"--For thouse with wings, fly to your dreams. |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2002-11-23 : 19:19:39
|
| The standard way of retriving data in asp.1. Create Connection2. Create Command3. Retrieve Recordset4. Process Recordset5. Close Connection6. Release ResourcesIf you know of a better way from asp 3.0 then please feel free to share.By the way if you're user id has apostrophes in it then your code will fail. |
 |
|
|
Eagle_f90
Constraint Violating Yak Guru
424 Posts |
Posted - 2002-11-23 : 19:23:43
|
| I know you have to make connections and close them but I was not asking how to make the connections. I was asking for the select string. And I know if there is an apostrophe in the UID it will fail but there no alowed to use apostrophes.--For thouse with wings, fly to your dreams. |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2002-11-23 : 21:41:01
|
quote: I know it can be done I just can't fugre out how.
quote: I have no idea why yours was so hard
quote: I know you have to make connections and close them but I was not asking how to make the connections. I was asking for the select string. And I know if there is an apostrophe in the UID it will fail but there no alowed to use apostrophes.
Edited by - ValterBorges on 11/24/2002 10:54:52 |
 |
|
|
|