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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DB Insert Prob???

Status
Not open for further replies.

ma701sd

IS-IT--Management
Dec 15, 2000
94
GB
Hi,
Can anyone cast a fresh pair of eyes over this one...

Im trying to insert only one item into a particular column in my database.
I conduct a query to select the appropriate the row (which is successful) but for some reason, the DB is not populated. ColdFusion does not report any errors though....?
Im passing via form variables..

Heres the code:
----------------------------------------------------------
CreatePage.cfm
<CFFORM ACTION=&quot;AuthenticateUser.cfm?cfid=#cfid#&amp;cftoken=#cftoken#&quot; METHOD=&quot;POST&quot;>
Please enter Your Username <CFINPUT TYPE=&quot;Text&quot; NAME=&quot;UserName&quot; REQUIRED=&quot;NO&quot;><BR>
Please ener your password <CFINPUT TYPE=&quot;password&quot; NAME=&quot;Password&quot; REQUIRED=&quot;NO&quot;><BR>
If you have forgotten your password <A href=&quot;ForgottenPassword.cfm&quot;> Retreive your Password </A>
<INPUT TYPE=&quot;submit&quot; VALUE=&quot;process&quot;>
----------------------------------------------------------
----------------------------------------------------------
InsertIntoDB.cfm
<CFQUERY DATASOURCE = &quot;ONLINE&quot; NAME = &quot;GetUser&quot;>
SELECT UserName
FROM Users
WHERE UserName = '#Client.UserName#'
</CFQUERY>

<head>
<title>Untitled</title>
</head>

<body>

<CFIF #GetUser.RecordCount# EQ 1>
<CFINSERT DATASOURCE = &quot;Online&quot;
TABLENAME = &quot;Users&quot;
FORMFIELDS = '#Form.Title#'>
</CFIF>


<CFOUTPUT>
Your website now has a heading of <B>#title#</b><BR>
</cfoutput>
---------------------------------------------------------

If anyne can help...PLEASE!!!!! :)

Thanks
Sam

<INPUT TYPE=&quot;reset&quot; VALUE=&quot;Clear&quot;>
 
There's two things about your code: the first is, why are you using Client.UserName in your query &quot;GetUser&quot; in InsertIntoDB.cfm? The variable is coming from a FORM, so refer to it by using FORM.UserName.
The reason why no data is inserted is possibly because the recordcount of the GetUser query is NOT 1. According to your code data only gets inserted if recordcount is 1. Check the recordcount, and PLEASE write a full SQL statement (INSERT INTO et cetera) since I think CFINSERT is bad ;-). Check other forums, and you'll see CFINSERT provides a lot of problems.
Hope this helps.
<webguru>iqof188</webguru>
 
Hi iqof188,
Thanks for your reply.
Im using client.username as this is a variable that I have set in my Application.cfm and is verified once the user has logged in i.e if the user login is succesful then a variable is set where CFSET form.username = client.username (I thunk this is right??)

Now about the inserting the data into my DB,
This is the error I get:
[Microsoft][ODBC Microsoft Access Driver] The field 'Users.PasswordReminderQuestion' cannot contain a Null value because the Required property for this
field is set to True. Enter a value in this field.

Data Source = &quot;Online&quot;

SQL = &quot;INSERT INTO Users ( `Title` ) VALUES ( ?)&quot;

Data Source = &quot;Online&quot;

The error occurred while processing an element with a general identifier of (CFINSERT), occupying document position (18:2) to (20:30).

Basically, i'm checking to make sure the user is a valid user within the database, If Yes then add the data else display an error message.. (it retrieves a record)
The query is successful, yet it does not enter the data.
WHats interesting is that the error (above)where passwordreminderquestion cannot be null does not make sense because this field is already populated. Is this a db setting?

Help!!!!!!!!!!!

Cheers
Sam
 
Hey Sam,

I'm a little confused by the code you posted. The first section has a form which calls a page called &quot;AuthenticateUser.cfm&quot; but you posted code for a page called &quot;InsertIntoDB.cfm&quot;. If authenticateuser then calls InsertIntoDB.cfm, it would help to see authenticateuser.cfm as well.

I see possibly two things that might be wrong. The first is that your Access database probably has the &quot;allow zero length&quot; option set to &quot;no&quot; on your &quot;PasswordReminderQuestion&quot; field. This would give you the error above when you try to insert a row with only data for the &quot;title&quot; field. Change this to &quot;yes&quot; and it shoudl eliminate that problem. It also appears that your data for the title field might not be coming across correctly but I can't tell without seeing the page which calls the &quot;insertIntoDB.cfm&quot; page.

GJ
 
I'm not sure I fully understand the problem then, but shouldn't the CFINSERT be a CFUPDATE? It seems to me you are trying to Add a value to the Title column in your database, right? Username, passwordreminderquestion and the other fields in your table are already there right? Sort out whether you need an insert or an update. Hope this helps!

<webguru>iqof188</webguru>
 
Hi Gunjack,
Yeah, that was me messing about with my code (experimenting though I cant think y!! :)

iqof188, Thanks...Problem Sorted!
I was being silly and could not see that I had to use an update instead of an insert SQL command. The row where I wanted to add data already had data so the only logical thing was an update!

Thanks everybody for your help !

Sam....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top