Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Define Unchecked Value in a Form
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Define Unchecked Value in a Form

 Post Reply Post Reply
Author
kennywhite View Drop Down
Groupie
Groupie


Joined: 26 February 2009
Location: Indy
Status: Offline
Points: 106
Post Options Post Options   Thanks (0) Thanks(0)   Quote kennywhite Quote  Post ReplyReply Direct Link To This Post Topic: Define Unchecked Value in a Form
    Posted: 15 March 2010 at 3:18pm
Hello.

I have a form with a checkbox. When the box is checked the form submits properly and all is good. When it is not checked I get this error message.

Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.

Here is the code for the check box:

<input name="completed" type="checkbox" id="completed" checked value="true">

The page that the data is posted to looks like this.

<% 'Dimension variables
Dim adoCon           'Holds the Database Connection Object 
Dim rsUpdateEntry    'Holds the recordset for the record to be updated
Dim strSQL           'Holds the SQL query to query the database 
Dim lngRecordNo      'Holds the record number to be updated


'Read in the record number to be updated
lngRecordNo = CLng(Request.Form("ID"))

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("projects.mdb")

'Create an ADO recordset object
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT projects.* FROM projects WHERE ID=" & lngRecordNo

'Set the cursor type we are using so we can navigate through the recordset
rsUpdateEntry.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rsUpdateEntry.LockType = 3

'Open the recordset with the SQL query 
rsUpdateEntry.Open strSQL, adoCon

'Update the record in the recordset







rsUpdateEntry.Fields("Completed") = Request.Form("Completed")






'Write the updated recordset to the database
rsUpdateEntry.Update

'Reset server objects
rsUpdateEntry.Close
Set rsUpdateEntry = Nothing
Set adoCon = Nothing

'Return to the update select page in case another record needs deleting
Response.Redirect "manage.asp"
%> 

Is there anything that I could easily change to fix this problem?


Thanks!
Back to Top
Scotty32 View Drop Down
Moderator Group
Moderator Group


Joined: 30 November 2002
Location: Manchester, UK
Status: Offline
Points: 1682
Post Options Post Options   Thanks (0) Thanks(0)   Quote Scotty32 Quote  Post ReplyReply Direct Link To This Post Posted: 16 March 2010 at 1:43pm

I wouldnt recommend entering the form data direct like that.

Add this to your form gathering section:
blnFormCompleted = CBool(Request.Form("Completed"))

Then change the update part like so:
rsUpdateEntry.Fields("Completed") = blnFormCompleted
S2H.co.uk - WebWiz Mods and Skins

For support on my mods + skins, please use my forum.
Back to Top
kennywhite View Drop Down
Groupie
Groupie


Joined: 26 February 2009
Location: Indy
Status: Offline
Points: 106
Post Options Post Options   Thanks (0) Thanks(0)   Quote kennywhite Quote  Post ReplyReply Direct Link To This Post Posted: 16 March 2010 at 5:00pm
I was unable to get that to work. I think I misunderstood where to place the code. Would you mind to point out the proper place for me?

Here is the entire code for the form page:

<%
'Dimension variables
Dim adoCon          'Holds the Database Connection Object
Dim rsProject    'Holds the recordset for the records in the database
Dim strSQL           'Holds the SQL query for the database
Dim lngRecordNo    'Holds the record number to be updated
           'Read in the record number to be updated
lngRecordNo = CLng(Request.QueryString("ID"))

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("projects.mdb")

'Create an ADO recordset object
Set rsProject = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT projects.* FROM projects WHERE ID=" & lngRecordNo

'Open the recordset with the SQL query
rsProject.Open strSQL, adoCon

thisContent = rsProject("Notes")
thisContent = replace(thisContent,"'","\'")
%>

<form name="F1" id="F1" method="post" action="update_entry2.asp">
<div id="form">
<table width="980">
<tr>
<td width="96">
<b>
Project Title:
</b>
</td><td width="894">

<input type="text" name="ProjectTitle" style="width:99%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<% = rsProject("ProjectTitle") %>"> </td>
</tr></table>

<table width="980">
<tr>
<td width="176">
<b>
Targeted Completion Date:
</b>
</td><td width="690">
<input type="text" name="TargetDate" style="width:10%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"value="<% = rsProject("TargetDate") %>"> </td>

<td width="1">
<b>
Priority:
</td><td width="9">
<input type="text" name="Priority" style="width:90%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"value="<% = rsProject("Priority") %>"> </td></tr></table>

<table>
<tr>
<td>
<b>
Details:</td> </tr></table>

<!-- #INCLUDE file="includes/FCKeditor/fckeditor.asp" -->
<%
Dim oFCKeditor
Set oFCKeditor = New FCKeditor
oFCKeditor.BasePath = "includes/FCKeditor/"
oFCKeditor.Create "notes"
%>
<script language="javascript" type="text/javascript">
<!--
window.onload = function()
{
document.F1.notes.value= ' <%=thisContent%> ' ;
}
-->
</script>
</td></tr></table><table width="980"><tr><td width="20">
<b>
Submitted By:
</td><td width="110">
<input type="text" name="SubmittedBy"style="width:90%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<% = rsProject("SubmittedBy") %>">
</td>
<td width="10">
<b>
On:
</td><td valign="center" width="100">
<input type="text" name="PostedDate" style="width:70%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;" value="<% = rsProject("PostedDate") %>">
</td>
<td width="130"> Project Complete <input name="completed" type="checkbox" id="completed" value="true" checked>
</td>
<td width="20">
<b>
Completeded By:
</td><td width="115">

<input type="text" name="CompletedBy"style="width:90%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"> </td>
<td width="10">
<b>
On:
</td><td valign="center" width="70">
<input type="text" name="CompletedDate" style="width:95%; height:16px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;">
</td>

<td valign="bottom" align="right" width="128">

<input type="hidden" name="ID" value="<% = rsProject("ID") %>">

 <br> <input type="submit" name="Submit" value="Submit">
</form>
</td>
</tr></table>
</div>
</form>
<!-- End form code -->
</body>
</html>
<%
'Reset server objects
rsProject.Close
Set rsProject = Nothing
Set adoCon = Nothing
%>






And here is the complete page where the data is processed.







[code]

<% 'Dimension variables
Dim adoCon           'Holds the Database Connection Object
Dim rsUpdateEntry    'Holds the recordset for the record to be updated
Dim strSQL           'Holds the SQL query to query the database
Dim lngRecordNo      'Holds the record number to be updated

'Read in the record number to be updated
lngRecordNo = CLng(Request.Form("ID"))

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("projects.mdb")

'Create an ADO recordset object
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT projects.* FROM projects WHERE ID=" & lngRecordNo

'Set the cursor type we are using so we can navigate through the recordset
rsUpdateEntry.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rsUpdateEntry.LockType = 3

'Open the recordset with the SQL query
rsUpdateEntry.Open strSQL, adoCon

'Update the record in the recordset

rsUpdateEntry.Fields("ProjectTitle") = Request.Form("ProjectTitle")
rsUpdateEntry.Fields("TargetDate") = Request.Form("TargetDate")

rsUpdateEntry.Fields("SubmittedBy") = Request.Form("SubmittedBy")

rsUpdateEntry.Fields("PostedDate") = Request.Form("PostedDate")

rsUpdateEntry.Fields("Priority") = Request.Form("Priority")

rsUpdateEntry.Fields("Notes") = Request.Form("Notes")

rsUpdateEntry.Fields("Completed") = Request.Form("Completed")

rsUpdateEntry.Fields("CompletedBy") = Request.Form("CompletedBy")
rsUpdateEntry.Fields("CompletedDate") = Request.Form("CompletedDate")

'Write the updated recordset to the database
rsUpdateEntry.Update

'Reset server objects
rsUpdateEntry.Close
Set rsUpdate
Back to Top
Scotty32 View Drop Down
Moderator Group
Moderator Group


Joined: 30 November 2002
Location: Manchester, UK
Status: Offline
Points: 1682
Post Options Post Options   Thanks (0) Thanks(0)   Quote Scotty32 Quote  Post ReplyReply Direct Link To This Post Posted: 20 March 2010 at 12:41pm
To be perfectly honest with you, it is hard to read through your entire page of code looking for the relevant parts.


As I said, you should avoid entering form values straight into the database.

I would recommend getting into the habit of structuring your pages so that you grab the values from the form, then enter into the database.

So you would add/alter the following in red:

lngRecordNo = CLng(Request.Form("ID"))
blnFormCompleted = CBool(Request.Form("Completed"))



rsUpdateEntry.Fields("Notes") = Request.Form("Notes")
rsUpdateEntry.Fields("Completed") = blnFormCompleted



This allows you to error check the entered fields, eg if a field is empty or to big you can display an error message instead of code error.

rsUpdateEntry.Fields("Completed") = Request.Form("Completed")
S2H.co.uk - WebWiz Mods and Skins

For support on my mods + skins, please use my forum.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.