GMMC_man
asked on
Error inserting hidden fields into sql db
I'm having difficulty inserting data into my sql database. I've got four fields; textAnswer, userID, assignmentID and date. None of these fields can contain NULL values. I'm getting the value for txtAnswer from the user, userID, assignmentID are coming from session variables and date is coming from <% date()%> . For some reason the normal insert statement is producing this error. Cannot insert the value NULL into column 'userID', table 'myClubonServer1.dbo.steps _answers'; column does not allow nulls. INSERT fails
Sounds like your session variable is null. are you using in-line SQL for the insert or stored procedures?
ASKER
I have the values printing out on the page just to make sure they are there. They are all showing up.
post that SQL statement here.
ASKER
<%
If (CStr(Request("MM_insert") ) = "frmWorkbook") Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnectio n = MM_connFCdata_STRING
MM_editCmd.CommandText = "INSERT INTO dbo.steps_answers (Answer1, userID, AssignmentID, UpdateDate) VALUES (?, ?, ?, ?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Appe nd MM_editCmd.CreateParameter ("param1", 201, 1, -1, Request.Form("txtAnswer")) ' adLongVarChar
MM_editCmd.Parameters.Appe nd MM_editCmd.CreateParameter ("param2", 5, 1, -1, MM_IIF(Request.Form("user" ), Request.Form("user"), null)) ' adDouble
MM_editCmd.Parameters.Appe nd MM_editCmd.CreateParameter ("param3", 5, 1, -1, MM_IIF(Request.Form("assig nment"), Request.Form("assignment") , null)) ' adDouble
MM_editCmd.Parameters.Appe nd MM_editCmd.CreateParameter ("param4", 135, 1, -1, MM_IIF(Request.Form("Updat eDate"), Request.Form("UpdateDate") , null)) ' adDBTimeStamp
MM_editCmd.Execute
MM_editCmd.ActiveConnectio n.Close
' append the query string to the redirect URL
Dim MM_editRedirectUrl
MM_editRedirectUrl = "AnswerProcess.asp?transID ="
If (Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
Response.Redirect(MM_editR edirectUrl )
End If
End If
%>
Here are the form fields
<textarea name="txtAnswer" cols="59" rows="8" id="txtAnswer" onblur="MM_validateForm('t xtAnswer', '','R');re turn document.MM_returnValue">< /textarea> </td>
<script type="text/javascript">
CKEDITOR.replace( 'txtAnswer' );
</script>
<input name="user" type="hidden" id="user" value="<%Session("MM_userI D")%>" />
<input name="assignment" type="hidden" id="assignment" value="<%Session("MM_Curre ntAssignme nt")%>" />
<input name="UpdateDate" type="hidden" id="UpdateDate" value="<% Date() %>" />
<input type="hidden" name="MM_insert" value="frmWorkbook" />
<input type="submit" name="btnNext" id="btnNext" value="Next" />
If (CStr(Request("MM_insert")
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnectio
MM_editCmd.CommandText = "INSERT INTO dbo.steps_answers (Answer1, userID, AssignmentID, UpdateDate) VALUES (?, ?, ?, ?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Appe
MM_editCmd.Parameters.Appe
MM_editCmd.Parameters.Appe
MM_editCmd.Parameters.Appe
MM_editCmd.Execute
MM_editCmd.ActiveConnectio
' append the query string to the redirect URL
Dim MM_editRedirectUrl
MM_editRedirectUrl = "AnswerProcess.asp?transID
If (Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
Response.Redirect(MM_editR
End If
End If
%>
Here are the form fields
<textarea name="txtAnswer" cols="59" rows="8" id="txtAnswer" onblur="MM_validateForm('t
<script type="text/javascript">
CKEDITOR.replace( 'txtAnswer' );
</script>
<input name="user" type="hidden" id="user" value="<%Session("MM_userI
<input name="assignment" type="hidden" id="assignment" value="<%Session("MM_Curre
<input name="UpdateDate" type="hidden" id="UpdateDate" value="<% Date() %>" />
<input type="hidden" name="MM_insert" value="frmWorkbook" />
<input type="submit" name="btnNext" id="btnNext" value="Next" />
seems like you don't want to be doing this IIF
MM_editCmd.Parameters.Appe nd MM_editCmd.CreateParameter ("param2", 5, 1, -1, MM_IIF(Request.Form("user" ), Request.Form("user"), null)) ' adDouble
MM_editCmd.Parameters.Appe
ASKER
I'm not a regular programmer.You are going to have to break it down to me.
Im not a web programmer, but the code looks like if the request.form("user") session variable is null, it just uses a NULL value.
ASKER
I'm not sure why that variable is not showing up int the form or the sql is not getting the info from the form. The variable is set and displaying.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.