Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing values entered in a form?

Status
Not open for further replies.

snivern

Programmer
Nov 30, 2003
9
US
Sorry guys, I know this is probably elementary. The book I bought for coldfusion doesn't really explain much. I created a form that takes 3 values(lastname, firstname, and phonenumber). After the user enters that info and clicks the submit button, I would like the database to be queried for those values and return the appropriate record to the results page. How can this be done? If I set a variable for each of these values, how do I get the info to the next page?
 
One thing you may want to consider is just using one of those items as a unique identifier to pass on to your results page if it will produce the desired results wither way. So your search form probably looks similar to this:

<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;yourresultspage.cfm&quot;>
First Name:
<input name=&quot;firstname&quot; type=&quot;text&quot;>
Last Name:<input name=&quot;Lastname&quot; type=&quot;text&quot;>
Phone Number:<input name=&quot;Phone&quot; type=&quot;text&quot;>
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Search&quot;>
</form>

Results Page:

<cfquery name=&quot;Userinfo&quot; datasource=&quot;Users&quot;>
SELECT desiredsfields FROM &quot;Tablename&quot; WHERE firstname = #FORM.form.firstname# AND lastname = #form.lastname# AND Phone = #form.phone#
</cfquery>

Then you could output your results like this:
<cfoutput query=&quot;userinfo&quot;
<table>
<tr>
<td>#userinfo.fieldyouwanttooutput#</td>
<td>#userinfo.fieldyouwanttooutput#</td>
<td>#userinfo.fieldyouwanttooutput#</td>

</tr>
</table>


Doing it this way will post the form variables from the search page to your results page.
 
does the
<cfquery name=&quot;Userinfo&quot; datasource=&quot;Users&quot;>
SELECT desiredsfields FROM &quot;Tablename&quot; WHERE firstname = #FORM.form.firstname# AND lastname = #form.lastname# AND Phone = #form.phone#
</cfquery>

have to be on the search page? Tried that and don't think that it recognized the previous page form when I entered it in.

<cfquery name=&quot;custresultsquery&quot; datasource=&quot;custdata&quot;>
SELECT *
FROM custdatatbl
WHERE custdatatbl.lastname = #custsearchform.lastname# and custdatatbl.firstname = #custsearchform.firstname#
and custdatatbl.phonenumber = #custsearchform.phonenumber#'
</cfquery>


Element LASTNAME is undefined in CUSTSEARCHFORM.


The error occurred in C:\CFusionMX\ line 4

2 : SELECT *
3 : FROM custdatatbl
4 : WHERE custdatatbl.lastname = #custsearchform.lastname# and custdatatbl.firstname = #custsearchform.firstname#
5 : and custdatatbl.phonenumber = #custsearchform.phonenumber#'
6 : </cfquery>

I really appreciate the help I've been getting. Thanks alot.
 
You're getting this error because CF doesn't know what the &quot;custsearchform&quot; scope is. If you're passing form variables, you need to specify the variables are coming from the form, so #custsearchform.lastname# should be #form.lastname#. All of your form variables need to be referenced this way.

Your select query should be on whatever page you have specified in the &quot;action&quot; attribute of your <form> (or <cfform>) tag.

Hope This Helps!

Ecobb

&quot;Alright Brain, you don't like me, and I don't like you. But lets just do this, and I can get back to killing you with beer.&quot; - Homer Simpson
 
I guess I don't know what you mean by passing form variables. the form on the search page is named custsearchform. the value of the textbox where I am placing the results would be custsearchform.lastname. Sounds right to me. I guess I am not getting something.
sorry, this is new to me. but what is the scope?
 
nvm, I got it but different error message, something's wrong with the select statement
i'll try to figure it out.
 
ok sorry about this, but the values are getting passed, but the error message say Too Few Parameters, Expected 2
Don't know what that means but here is my query statement.

SELECT *
FROM custdatatbl
WHERE custdatatbl.lastname = #form.lastname# and custdatatbl.firstname = #form.firstname#
and custdatatbl.phonenumber = #form.phonenumber#
 
You have to put single quotes around variables with text.

WHERE custdatatbl.lastname = #form.lastname# and custdatatbl.firstname = #form.firstname#
and custdatatbl.phonenumber = #form.phonenumber#

Should be:

WHERE custdatatbl.lastname = '#form.lastname#' and custdatatbl.firstname = '#form.firstname#'
and custdatatbl.phonenumber = '#form.phonenumber#'

Actually, the quotes around the form.phonenumber variable will depend on what datatype it is in the database. If it's a numeric datatype, you won't need the quotes. If it's text, or char, or varchar, etc... you will need the quotes.


Hope This Helps!

Ecobb

&quot;Alright Brain, you don't like me, and I don't like you. But lets just do this, and I can get back to killing you with beer.&quot; - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top