-
June 13th, 2013, 10:16 AM
#16
Re: Error code help needed
If your goal is to add a record then you are going about it wrong. Select is used to query the database and return a record that is there.
To add a record you should use the Insert statement and check the return code to see if it added a record or you can use select to see if the record is there first and then if it is not there you could use either an Insert or you could use an RS.Addnew
The last code you posted is very hard to follow even after I added the code tags but I do not see any where a record is being added, I did see one place where it would try to update a record.
Always use [code][/code] tags when posting code.
-
June 13th, 2013, 02:37 PM
#17
Re: Error code help needed
-
June 13th, 2013, 07:33 PM
#18
Re: Error code help needed
The only code I saw in there that would modify the data is this
Code:
Dim TypeRS
Query = "SELECT * FROM Type WHERE TypeId=" & Request("TypeId")
Set TypeRS = Server.CreateObject("ADODB.Recordset")
TypeRS.Open Query, Connect, 2, 3
TypeRS("TypeName") = Request("TypeName")
TypeRS("TypeColor") = Request("LinkColor")
TypeRS.Update
TypeRS.Close()
That code would update the data in a specific record if the record exists otherwise it would throw an error i.e. No current record
The same method can be used to add a new record but requires you to use the RS.AddNew method
From what you have posted I do not see any way that a new record would be added to the database unless I missed something. Is hard to read buried in with all the html code.
Could it be that you posted the code from the edit form rather than the add form?
Always use [code][/code] tags when posting code.
-
June 13th, 2013, 09:14 PM
#19
Re: Error code help needed
Originally Posted by DataMiser
The only code I saw in there that would modify the data is this
Code:
Dim TypeRS
Query = "SELECT * FROM Type WHERE TypeId=" & Request("TypeId")
Set TypeRS = Server.CreateObject("ADODB.Recordset")
TypeRS.Open Query, Connect, 2, 3
TypeRS("TypeName") = Request("TypeName")
TypeRS("TypeColor") = Request("LinkColor")
TypeRS.Update
TypeRS.Close()
That code would update the data in a specific record if the record exists otherwise it would throw an error i.e. No current record
The same method can be used to add a new record but requires you to use the RS.AddNew method
From what you have posted I do not see any way that a new record would be added to the database unless I missed something. Is hard to read buried in with all the html code.
Could it be that you posted the code from the edit form rather than the add form?
Thanks again my friend.... I am no sure what I have done now .... confused?...but I will take all you have said and review each module carefully . I really hope I have supplied the correct code or I am going to be really embarrassed. I'll begin right now. Thanks again and ..... watch this spot...
-
June 14th, 2013, 03:48 PM
#20
Re: Error code help needed
Originally Posted by davida1956
Thanks again my friend.... I am no sure what I have done now .... confused?...but I will take all you have said and review each module carefully . I really hope I have supplied the correct code or I am going to be really embarrassed. I'll begin right now. Thanks again and ..... watch this spot...
Hi ..... I've had a trawl through my .asp routines and am not sure which code may be of help here. I have noted that the category_add.asp file which does as it says, has the following code
[%>
<td width="185" height="19" align="right" valign="middle" nowrap><p align="right"><strong>ADD NEW CATEGORY : </strong></p></td>
<td width="215"> <p>
<input name="TypeName" type="text" class="form" value="" size="25" maxlength="25">
</p></td>
</tr>
<tr valign="baseline">
<td height="16" align="right" valign="middle" nowrap> </td>
<td> </td>
</tr>
<tr valign="baseline">
<td height="24" align="right" valign="middle" nowrap><p align="right"><strong>CATEGORY LINK COLOR : </strong></p></td>
<td> <p>
<select name="LinkColor">
<%
Dim LinkColorRS
Set LinkColorRS = Server.CreateObject("ADODB.Recordset")
LinkColorRS.Open "SELECT * FROM LinkColor", Connect, 3, 3
While (Not LinkColorRS.EOF)
Response.Write "<option STYLE='color: " & LinkColorRS("ColorCode") & " !important' value='" & LinkColorRS("ColorCode") & "'>" & LinkColorRS("ColorName") & "</option>"
LinkColorRS.MoveNext
Wend
%>
</select>
</p></td>
</tr>
<tr valign="baseline">
<td height="16" align="right" nowrap> </td>
<td> </td>
</tr>
<tr valign="baseline">
<td height="22" align="right" nowrap> </td>
<td> <p>
<input name="Add" type="submit" class="form" id="Add" value="Add">
</p></td>
]
This bit of code allows you to name a new category and attach a colour to that test, it then posts and populates the database. The following bit of code comes from the next bit of code come from the category_edit.asp file and should allow me to edit the category information...change the name and link colour, which it does but it doesn't seem to perform the test 'Check for empty field' and so doesn't throw out the error message show.
From category_edit.asp
[<%
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If Request("TypeName")="" Then
If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Else
' If Flag isn't true, show the edit form:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
End If
%>
]
the last bit of code is from the category_add.asp
[
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td align="left" valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td align="center" valign="middle"><p class="text">The category "<% Response.Write Request("TypeName")%>" has been added to the database.</p></td>
</tr>
<tr>
<td align="center" valign="top"></td>
</tr>
</table>
</td>
</tr>
</table>
<%
CategoryRS.Close()
Response.Redirect("category.asp")
%>
]
This is supposed to check that the category that the correct data has been put into the field and report that a new record has been added to the database. This bit also doesn't work and I can't pin down which bit of code affects the other so that none of them perform at 100%. I don't know if this lot helps in any way or not ? It may only give you a bit of an sight but could point to a fault somewhere else? Is there anything else I can provide or do to try and pin the fault down please. Thanks again for your help
David A
-
June 14th, 2013, 06:41 PM
#21
Re: Error code help needed
I still do not see anything there that would add a record. In fact there is nothing in that last post that would update a record either.
There are 2 basic ways to add a record to the database
1:
Code:
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
CategoryRs.AddNew ' If you want to edit then you would omit this line
' some code to set the field values
CategoryRS.Update
2:
Code:
connect.Execute "Insert Into [Type] (Fieldname1,FieldName2) Values (Value1,Value2)"
There is also a third method using parametrized queries. A quick search should turn up some examples.
Always use [code][/code] tags when posting code.
-
June 16th, 2013, 06:41 AM
#22
Re: Error code help needed
Originally Posted by DataMiser
I still do not see anything there that would add a record. In fact there is nothing in that last post that would update a record either.
There are 2 basic ways to add a record to the database
1:
Code:
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
CategoryRs.AddNew ' If you want to edit then you would omit this line
' some code to set the field values
CategoryRS.Update
2:
Code:
connect.Execute "Insert Into [Type] (Fieldname1,FieldName2) Values (Value1,Value2)"
There is also a third method using parametrized queries. A quick search should turn up some examples.
Hi... thanks for the pointers, I think I have perhaps pinned down the code but cannot be sure of it. I have tried to describe what I think the code should do an....d associate lines of code from the 3 .asp pages
The addition of a category is controlled from an interface script called ‘category.asp’ which I believe handles 2 variables… both held in the .mdb for the ADD and Link_Colour.
CODE FROM --CATEGORY.ASP SCRIPT
{<%
Dim LinkColorRS
Set LinkColorRS = Server.CreateObject("ADODB.Recordset")
LinkColorRS.Open "SELECT * FROM LinkColor", Connect, 3, 3
While (Not LinkColorRS.EOF)
Response.Write "<option STYLE='color: " & LinkColorRS("ColorCode") & " !important' value='" & LinkColorRS("ColorCode") & "'>" & LinkColorRS("ColorName") & "</option>"
LinkColorRS.MoveNext
Wend
%>}
{
<%
' Display current categories along with the number of events in each category:
Dim rsTypes, rsTypes_numRows
set rsTypes = Server.CreateObject("ADODB.Recordset")
rsTypes.Open "SELECT *, (SELECT COUNT(*) FROM Events WHERE EventType = TypeId) AS EVE_COUNT FROM Type ORDER BY TypeName ASC", Connect, 3, 3
rsTypes_numRows = 0
Dim HLooper1__numRows
HLooper1__numRows = -2
Dim HLooper1__index
HLooper1__index = 0
rsTypes_numRows = rsTypes_numRows + HLooper1__numRows
%>
}
This next part of the script is from the … category_add.asp code which I think receives the information from the Category.asp Interface and posts it to the .mdb and the returns to the category.asp to display the result
The category.asp script also displays existing categories, which allows me the option to delete any of them and this part of the coding works.
For example
If I call for a new category …. ‘TEST’… the function follows the routine and adds the details to the database in the correct fields and in the correct format it also displays the new category on the ‘category.asp’ script, but does NOT display the message advising that the Category ‘TEST’ has been added to the database. I assume that the code to do this, which is shown below and copied from the above code, may not be correct ??
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If Request("TypeName")="" Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Else
' If Flag isn't true, show the edit form:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
End If
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td align="left" valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td height="205" align="left" valign="middle"><p> </p><form method="POST" action="<%= Request.ServerVariables("URL") %>" name="ADD">
<table align="center" class="textBold">
<tr valign="baseline">
<td width="170" height="21" align="right" valign="middle" nowrap><span class="text">EDIT CATEGORY NAME:</span> </td>
<td width="313"> <input name="TypeName" type="text" class="form" value="<%=CategoryRS("TypeName")%>" size="50" maxlength="50">
</td>
</tr>
<tr valign="baseline">
<td height="42" align="right" valign="middle" nowrap> </td>
<td> </td>
</tr>
<tr valign="baseline">
<td height="24" align="right" valign="middle" nowrap class="text">CATEGORY LINK COLOR: </td>
<td> <select name="LinkColor">
<%
Dim LinkColorRS
Set LinkColorRS = Server.CreateObject("ADODB.Recordset")
LinkColorRS.Open "SELECT * FROM LinkColor", Connect, 3, 3
While (Not LinkColorRS.EOF)
Response.Write "<option STYLE='color: " & LinkColorRS("ColorCode") & " !important' value='" & LinkColorRS("ColorCode") & "'"
If (CategoryRS("TypeColor") = LinkColorRS("ColorCode")) Then Response.Write "selected"
Response.Write">" & LinkColorRS("ColorName") & "</option>"
LinkColorRS.MoveNext
Wend
LinkColorRS.Close()
CategoryRS.Close()
%>
</select>
</td>
</tr>
<tr valign="baseline">
<td height="24" align="right" nowrap> </td>
<td> <p>
</p>
<p>
<input name="Submit" type="submit" class="form" id="Submit" value="Submit">
</p></td>
</tr>
</table>
<input type="hidden" name="Flag" value="True">
<input type="hidden" name="TypeId" value="<%=Request("iType")%>">
</form>
<%
' If the form has been submitted (Flag = True), and the Category Name field isn't empty, update the record:
Else
Dim TypeRS
Query = "SELECT * FROM Type WHERE TypeId=" & Request("TypeId")
Set TypeRS = Server.CreateObject("ADODB.Recordset")
TypeRS.Open Query, Connect, 2, 3
TypeRS("TypeName") = Request("TypeName")
TypeRS("TypeColor") = Request("LinkColor")
TypeRS.Update
TypeRS.Close()
Response.Redirect("category.asp")
End If
%>
{The category "<% Response.Write Request("TypeName")%>" has been added to the database.</p></td>}
If I enter a null value for the category name it still enters that data to the .mdb and displays it with (0) associated records. It also does not display the associated error message which is held in the category_add .asp code..At some point control is passed over to the category_add.asp module to be verified. I think this is the code it uses :-
CODE SECTION FROM -- CATEGORY_ADD.ASP
{
' *** Insert new category, name and link color:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type", Connect, 2, 3
CategoryRS.AddNew
CategoryRS("TypeName") = Request("TypeName")
CategoryRS("TypeColor") =Request("LinkColor")
CategoryRS.Update
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td align="left" valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td align="center" valign="middle"><p class="text">The category "<% Response.Write Request("TypeName")%>" has been added to the database.</p></td>
</tr>
<tr>
<td align="center" valign="top"></td>
</tr>
</table>
</td>
</tr>
</table>
<%
CategoryRS.Close()
Response.Redirect("category.asp")
%>
}
There is only 1 other module associated with category issue and that is category_edit.asp. It gathers information from the two other modules and displays the information correctly (even if it is blank) I can then change the associated fields by adding, editing or removing, dates, details and categories. This seems to work fine. If the new category is still left empty then it still enters it back to the .mdb. I presume this is because the above section of code shown above has some sort of error? This is the code script from the category_edit.asp that I think looks for the conditions…
CODE SECTION FROM CATEGORY_EDIT.ASP
{
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If Request("TypeName")="" Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Else
' If Flag isn't true, show the edit form:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
End If
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td align="left" valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td height="205" align="left" valign="middle"><p> </p><form method="POST" action="<%= Request.ServerVariables("URL") %>" name="ADD">
<table align="center" class="textBold">
<tr valign="baseline">
<td width="170" height="21" align="right" valign="middle" nowrap><span class="text">EDIT CATEGORY NAME:</span> </td>
<td width="313"> <input name="TypeName" type="text" class="form" value="<%=CategoryRS("TypeName")%>" size="50" maxlength="50">
</td>
</tr>
<tr valign="baseline">
<td height="42" align="right" valign="middle" nowrap> </td>
<td> </td>
</tr>
<tr valign="baseline">
<td height="24" align="right" valign="middle" nowrap class="text">CATEGORY LINK COLOR: </td>
<td> <select name="LinkColor">
<%
Dim LinkColorRS
Set LinkColorRS = Server.CreateObject("ADODB.Recordset")
LinkColorRS.Open "SELECT * FROM LinkColor", Connect, 3, 3
While (Not LinkColorRS.EOF)
Response.Write "<option STYLE='color: " & LinkColorRS("ColorCode") & " !important' value='" & LinkColorRS("ColorCode") & "'"
If (CategoryRS("TypeColor") = LinkColorRS("ColorCode")) Then Response.Write "selected"
Response.Write">" & LinkColorRS("ColorName") & "</option>"
LinkColorRS.MoveNext
Wend
LinkColorRS.Close()
CategoryRS.Close()
%>
</select>
</td>
</tr>
<tr valign="baseline">
<td height="24" align="right" nowrap> </td>
<td> <p>
</p>
<p>
<input name="Submit" type="submit" class="form" id="Submit" value="Submit">
</p></td>
</tr>
</table>
<input type="hidden" name="Flag" value="True">
<input type="hidden" name="TypeId" value="<%=Request("iType")%>">
</form>
<%
' If the form has been submitted (Flag = True), and the Category Name field isn't empty, update the record:
Else
Dim TypeRS
Query = "SELECT * FROM Type WHERE TypeId=" & Request("TypeId")
Set TypeRS = Server.CreateObject("ADODB.Recordset")
TypeRS.Open Query, Connect, 2, 3
TypeRS("TypeName") = Request("TypeName")
TypeRS("TypeColor") = Request("LinkColor")
TypeRS.Update
TypeRS.Close()
Response.Redirect("category.asp")
End If
%>
Does this help any or am I still missing something ……many regards
David A.
-
June 16th, 2013, 10:23 AM
#23
Re: Error code help needed
This is the part that would add a record
Code:
*** Insert new category, name and link color:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type", Connect, 2, 3
CategoryRS.AddNew
CategoryRS("TypeName") = Request("TypeName")
CategoryRS("TypeColor") =Request("LinkColor")
CategoryRS.Update
You are trying to display a message here
<td align="center" valign="middle"><p class="text">The category "<% Response.Write Request("TypeName")%>" has been added to the database.</p></td>
but here you move off the page so that message will not be seen by the user
CategoryRS.Close()
Response.Redirect("category.asp")
Rather than having that redirect there you may want to consider adding an OK button or link that will go to the desired page when the user clicks on it and therefore allow the message to be displayed for the user to see.
Always use [code][/code] tags when posting code.
-
June 16th, 2013, 07:29 PM
#24
Re: Error code help needed
Originally Posted by DataMiser
This is the part that would add a record
Code:
*** Insert new category, name and link color:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type", Connect, 2, 3
CategoryRS.AddNew
CategoryRS("TypeName") = Request("TypeName")
CategoryRS("TypeColor") =Request("LinkColor")
CategoryRS.Update
You are trying to display a message here
but here you move off the page so that message will not be seen by the user
Rather than having that redirect there you may want to consider adding an OK button or link that will go to the desired page when the user clicks on it and therefore allow the message to be displayed for the user to see.
Hi again and thanks ever so much for pinpointing the problem, you make it sound so easy... you certainly are a Guru !! and this is some Forum... I am well impressed at the help you have offered and given freely to a fellow member... that news will travel. I will try to do as you suggest and let you know how it goes. I guess the same sort of procedure should be used to see the other advice / error message as well. OK... I will get stuck in now I have some spare time again... thanks a million my friend... David A
-
June 16th, 2013, 09:44 PM
#25
Re: Error code help needed
Originally Posted by davida1956
Hi again and thanks ever so much for pinpointing the problem, you make it sound so easy... you certainly are a Guru !! and this is some Forum... I am well impressed at the help you have offered and given freely to a fellow member... that news will travel. I will try to do as you suggest and let you know how it goes. I guess the same sort of procedure should be used to see the other advice / error message as well. OK... I will get stuck in now I have some spare time again... thanks a million my friend... David A
A little later.....Fantastic .. I followed you suggestion and simply added a hidden button. All information is still handed over to the .mdb correctly and the message approving it shown. The only issue left is that it doesn't detect the " " String value and trap it but also adds it to the database. The code I've shown below looks fine to me so I have no idea why it shouldnot work??Unless...... the value given is empty which it also still adds.
[
<%
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If Request("TypeName")="" Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Else
' If Flag isn't true, show the edit form:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
End If
%>
]
This is where explorer bombs out and says it can't find the given value. Any suggestions? I'll keep at it and see if I can make it do something that will help me understand things a little clearer.
David A
-
June 17th, 2013, 09:29 AM
#26
Re: Error code help needed
The only issue left is that it doesn't detect the " " String value
If Request("TypeName")="" Then
You are trapping for an empty string so a string with one or more space will not be picked up by this.
If you want to also filter out strings that maybe be nothing but 1 or more spaces as well then you would use a trim() function
Code:
If Trim(Request("TypeName"))="" Then
Trim removes all spaces from the right and left of a string
Always use [code][/code] tags when posting code.
-
June 17th, 2013, 11:10 AM
#27
Re: Error code help needed
Originally Posted by DataMiser
You are trapping for an empty string so a string with one or more space will not be picked up by this.
If you want to also filter out strings that maybe be nothing but 1 or more spaces as well then you would use a trim() function
Code:
If Trim(Request("TypeName"))="" Then
Trim removes all spaces from the right and left of a string
Hi again and thanks a million for your reply. I do actually want to check for an empty string. If the field is empty then it should throw out an error message but it doesn't and the code looks fine to me so I am a bit confused.... I'm not too worried about padding or spaces in this section as only the 'admin' has access to it through the web interface, but Ican use that little gem you suggested in another function of the coding :-) any ideas?
-
June 17th, 2013, 09:03 PM
#28
Re: Error code help needed
In that case you just need to follow the code through from the point where the message is displayed by your code and see what it does after that. It is to hard to read it on here without code tags and proper indenting. Perhaps you have a redirect somewhere after the message that causes it to go to another page without actually giving the display like was the case in the add record part.
But then in your previous message you said
The only issue left is that it doesn't detect the " " String value
Which is not an empty string and will not be detected as one unless you trim the spaces off of it like I showed in my last post.
Always use [code][/code] tags when posting code.
-
June 21st, 2013, 06:00 PM
#29
Re: Error code help needed
Originally Posted by DataMiser
In that case you just need to follow the code through from the point where the message is displayed by your code and see what it does after that. It is to hard to read it on here without code tags and proper indenting. Perhaps you have a redirect somewhere after the message that causes it to go to another page without actually giving the display like was the case in the add record part.
But then in your previous message you said
Which is not an empty string and will not be detected as one unless you trim the spaces off of it like I showed in my last post.
Hi again... Just got back to where I was a few days ago. I had to backtrack because whilst testing it out I found that things were corrupting the database and some scripts wouldn't run at all. I've spent a few days catching up with myself to the point where I have been trying to do the 'Trim' you explained. I assume I haven't done any damage as there is no fault in any of the modules right now. It still doesn't detect the empty string despite the trim and still adds "" to the category table. I am trying to trace my way through the rest of the code to see if I can spot a problem. It is a bit muddled up...mind you .. so am I ..... :-)
-
June 22nd, 2013, 04:50 PM
#30
Re: Error code help needed
Well you are not testing it where you add a record
Code:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type", Connect, 2, 3
CategoryRS.AddNew
CategoryRS("TypeName") = Request("TypeName")
CategoryRS("TypeColor") =Request("LinkColor")
CategoryRS.Update
You are testing it somewhere else but if you do not want the record added under these conditions then you need to test where you are adding the record.
Always use [code][/code] tags when posting code.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|