Cannot get data from MS SQL database using ColdFusion -
i'm using coldfusion , trying data ms sql database. problem there should 1 line details. @ same time if i'm trying login user or admin works fine. syntax same admin login. maybe i've missed something? here's code:
<html> <head> <cfquery name='query' datasource='mydsn'> <cfset "id" = #form.user#/> select userid, fname, sname, phone, address users userid = <cfqueryparam value="#form.user#" cfsqltype="cf_sql_varchar"> </cfquery> </head> <body> <cfif #query.recordcount# eq 1> <table height="30px" cellpadding="5" cellspacing="3"> <tr bgcolor="888888" > <th>user id </th> <th>name </th> <th>surname </th> <th>phone </th> <th>address </th> </tr> <td><cfoutput> #query.userid# </cfoutput></td> <td><cfoutput> # query.fname# </cfoutput></td> <td><cfoutput> # query.sname# </cfoutput></td> <td><cfoutput> # query.phone# </cfoutput></td> <td><cfoutput> # query.address# </cfoutput></td></tr> <cfelse> <cfoutput> no such user...</cfoutput> </cfif> </body> </html>
your original query , error message not same code. error message shows you're listing column names in statement. correct syntax.
<cfquery name='query' datasource='mydsn'> select userid, fname, sname, phone, address users userid = <cfqueryparam value="#trim(form.user)#" cfsqltype="cf_sql_varchar"> </cfquery from leigh's chat - make sure you're not adding in leading/trailing zeroes when using cfqueryparam.
also, in cfif statement, # not needed.
<cfif query.recordcount eq 1> to fix issue output not working
<cfif query.recordcount eq 1> <cfoutput> <table height="30px" cellpadding="5" cellspacing="3"> <tr bgcolor="888888" > <th>user id</th> <th>name</th> <th>surname</th> <th>phone</th> <th>address</th> </tr> <tr> <td>#query.userid#</td> <td>#query.fname#</td> <td>#query.sname#</td> <td>#query.phone#</td> <td>#query.address#</td> </tr> </cfoutput> <cfelse> <cfoutput> #form.user#</cfoutput> </cfif>
Comments
Post a Comment