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!

CFC and sql inserting data into access ddb 3

Status
Not open for further replies.

DuncanKing

Programmer
Jan 14, 2004
32
IE
I have created a web service to enter data into an access db with the following cfc page.
I'm calling this with a cfm page and a cfinvoke tag and URL I get the "Congrats Inserted!!" message returned when I submit the form but no data goes into the access db. Any ideas where the problem might be?
Thanks DK

<!---start addBooking.cfc page--->
<cfcomponent>
<cffunction name="testFunct" access="remote" returntype="string">
<cfargument name="x" type="struct" required="true">
<cfquery datasource="cars_autoselect_ca" >
Insert Into bbBooking (name, address, tel, description, accommodation, price, availability)
Values ('#name#', '#address#', '#tel#' '#description#' '#accommodation#', '#price#', '#availability#' )
</cfquery>
<cfreturn x.name>
</cffunction>
</cfcomponent>
<!---end addBooking.cfc page--->


<!---start of addBooking.cfm page that calls the cfc--->
<cfif IsDefined("myvar")>
<cfscript>
myvar = StructNew();
myvar["name"] = URL.name;
myvar["address"] = URL.address;
myvar["tel"] = URL.tel;
myvar["description"] = URL.description;
myvar["accommodation"] = URL.accommodation;
myvar["price"] = URL.price;
myvar["availability"] = URL.availability;
</cfscript>


<cfinvoke
webservice=" method="testFunct"
returnvariable="aString" >
<cfinvokeargument name="x" value="#myvar#" />
</cfinvoke>
</cfif>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Sean Test</title>
</head>

<body>
<cfif IsDefined("URL.name")> Congrats Inserted!! </cfif>

<form action="addBooking.cfm" method="get" >

<table width="90%" border="1">
<tr>
<td>name</td>
<td><input name= "name" type="text" id="name"></td>
</tr>
<tr>
<td>add</td>
<td><input type="text" name= "address" id="address" value="enter you address"></td>
</tr>
<tr>
<td>tel</td>
<td><input type="text" name="tel" id="tel"></td>
</tr>
<tr>
<td>description</td>
<td><input name="description" type="text" id="description"></td>
</tr>

<tr>
<td>accommodation</td>
<td><input name="accommodation" type="text" id="accommodation"></td>
</tr>

<tr>
<td>price</td>
<td><input name="price" type="text" id="price"></td>
</tr>

<tr>
<td>availability</td>
<td><input name="availability" type="text" id="availability"></td>
</tr>

</table>
<p>
<input type="submit" value="Submit" name="form1" >
</p>
</form>
</body>
</html>
<!---end addBooking.cfm page--->
 
Duncan,

You're not referencing your variable correctly in your webservice. As the variable X is a structure you can't just use #Name#.

Change your values in the insert statement to this:

Code:
Values ('#x.name#', '#x.address#', '#x.tel#' '#x.description#' '#x.accommodation#', '#x.price#', '#x.availability#' )

Hope this helps!

Tony
 

Tony,

Thanks for this! I've made the changes and still no data going into DB. I've also checked my DSN and this is correct. I tried it with "post" and "get" methods in the form. Notice that form action is action="addBooking.cfm" which is the same page the form is in. It's also where I'm calling the webservice and cfc file so I think that's OK?
Strange thing is I get no errors. I just get the addBooking.cfm page returned when I submit the form with "Congrats Inserted!!"

DK
 
cffunction creates a udf. similar to cfscript only you can use cftags inside cffunction. you create a udf called testFunct() but i don't see where you actually call the function to make it work.

here is the live docs page on cffunction


A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
I called testFunct with the cfinvoke tag and the method attribute in the addBooking.cfm page (see below). I have the 2 required attributes, name and type, the in cfargument tag in the the cfc page?


<cfinvoke webservice=" method="testFunct"
returnvariable="aString" >
<cfinvokeargument name="x" value="#myvar#" />
</cfinvoke>
 
oops. i guess you did, sorry missed that part. try a cfoutput inside the function to see if it is being called properly.

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
The problem might be with data types or with reserved field names. Are all the fields text fields? If not, you shouldn't have single quotes around that variable in the insert statement.
 
Yes all text fields but I do have a primary "ID" key in the DB which does not have an input field in the form.
 
You're missing commas in your insert statement after '#tel#' and '#description#'

<cfquery datasource="cars_autoselect_ca" >
Insert Into bbBooking (name, address, tel, description, accommodation, price, availability)
Values ('#name#', '#address#', '#tel#', '#description#', '#accommodation#', '#price#', '#availability#' )
</cfquery>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top