-
[RESOLVED] Error code help needed
Hi Folks.. I am a real newbie to this... no real knowledge about programming but keen to learn. I am playing with some code at the moment that should return a message that a 'category' has been added to an Access Database and another bit checking to see that if a no value is entered it writes an error message. I can't get the **** thing to work and think I may have tried to run before I can walk. saying that if there are no values. The error message I get is ...
Microsoft JET Database Engine error '80040e14'
Syntax error (missing operator) in query expression 'TypeId ='.
it makes reference to line 67 in the code but I can't find anything there that may be wrong
and the code I am using is
<%
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
%>
Sorry for being such a thicko but can anybody out there please help me ???
thanks to you all who take an interest in these and help us newbies sort things out.....
Regards
David A
-
Re: Error code help needed
What value is in iType?
Is TypeID a text field or numeric field in the db?
-
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
What value is in iType?
Is TypeID a text field or numeric field in the db?
Hi and thank you so much for a prompt reply I really appreciate it. Here is a copy of what the .mdb file holds.
TypeId TypeName TypeColor
966 BOOKED #F00
968 Enquiries #CCC
973 MDA #00F
977 TEST #000
I'm keen to try and learn so any pointers and advice you can give would be great. This is even my first attempt at joining a forum! I was made redundant so have to find something to fill my time in otherwise go mad.
Regards
David A
-
Re: Error code help needed
-
Re: Error code help needed
Unfortunately you did not answer either of my questions.
I assume based on the data and field name that TypeID is a numeric field but I can only guess since you did not say.
You also did not say what value is held in iType
My guess would be that it is empty and that would trigger an error with a numeric field type.
-
Re: Error code help needed
Hi DataMiser.... sorry but am still finding my way around .. TypeID is a numeric value held in my .mdb and looks like this
TypeId TypeName TypeColor
966 BOOKED #F00
968 Enquiries #CCC
973 MDA #00F
977 TEST #000
The code does actually enter the the record but does not confirm it has done so nor does it confirm the action of deleting the record.
I not I need to use [ ] to show code so here is my first shot at it
Code:
<%
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
%>
if that doesn't work can you please let me know :-) Thanks 100 %
David A
-
Re: Error code help needed
You still did not tell us what value is in iType when the code is executed,
Quote:
WHERE TypeId =" & Request("iType")
If iType is blank you will get an error
Also you told us the field in the db contains numeric data but we could already see that, the question was is the field a numeric field. Numeric fields can only contain numbers, text fields can contain numbers as well so having numeric data does not always mean the field is numeric but I will assume that it is.
-
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
You still did not tell us what value is in iType when the code is executed,
If iType is blank you will get an error
Also you told us the field in the db contains numeric data but we could already see that, the question was is the field a numeric field. Numeric fields can only contain numbers, text fields can contain numbers as well so having numeric data does not always mean the field is numeric but I will assume that it is.
Hi and thanks so much for your patience with me and of course the speedy reply. Please bare with me as I'm on a rapid learning curve... Yes the TypeId field is defined as being a numeric auto-increment field which I guess is right. As for the iType I'm struggling to answer that. What should happen is if the field is left empty you should get the error message advising of that and be prompted to input a value. If a value is given then I presume it is called iType and a message advising that 'the data given' has been added to the database. Neither messages work but the information is still passed to the database. I think I understand how it should work but just don't have the skills yet to debug the software. Is this of any help and if not is there anything else I can do to help understand the problem at both ends of the spectrum... Newbie-----Expert... Again... thanks a million guys
David A
-
Re: Error code help needed
Your code checks to see if typename is an empty string if it is then it displays a message if it is not then it executes a select statement which uses iType as a where clause but your script does not test the value of iType so it would process it no matter what the value or lack of a value and looks to be the cause of the error. See the lines in Red
Code:
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
I am assuming that this is a server side ASP script and that iType is the name of an object that is on a form that been posted?
-
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
Your code checks to see if typename is an empty string if it is then it displays a message if it is not then it executes a select statement which uses iType as a where clause but your script does not test the value of iType so it would process it no matter what the value or lack of a value and looks to be the cause of the error. See the lines in Red
Code:
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
I am assuming that this is a server side ASP script and that iType is the name of an object that is on a form that been posted?
Hi and once again many thanks for your reply. You are bang on with the understanding that this is a server side .asp script. It uses an admin panel to update, add or edit given categories. I have checked through things and noted that even when you enter a "" value the category is added to the database with the default colour of black. None of the other fields contain information. iType is a value held in one of the fields labelled EventType in the .db which contains a value of "0" when entered without a category name. I though that if the category had not been named then the code should have returned an error message and not updated the .db with a prompt to correct it. If I try to access this .db through my browser then I am able to see that the error points to a value with iType. What I don't understand is how to check for an invalid entry when the code to do it is there. Do I need to modify the code or the .db? As mentioned... newbie struggling with basics here :-( thanks so much for your help so far, very commendable and forums seem to be the place to get expert help, reassuring to know there is somebody out there that takes an interest in newcomers.:thumb: I'm going to get stuck into the code again and try to understand what it is doing, where and when. Maybe I can insert some form of debugging script in to pinpoint what I need to do and where ???
regards
David A
-
Re: Error code help needed
An autonumber field populates automatically when you add a record. You can not select using a numeric field in a where clause without a valid numeric value as part of that clause.
to test it you could use IsNumeric()
Code:
If Request("TypeName")="" Then
If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Elseif IsNumeric(Request("iType")) Then
' 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
Else
' display some message stating that the type id is not valid
End If
Or maybe you need to change the select statement to use the TypeName instead, just depends on what you want it to return. TypeID should never return more than 1 record, TypeName may return more than one depending on your data
-
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
An autonumber field populates automatically when you add a record. You can not select using a numeric field in a where clause without a valid numeric value as part of that clause.
to test it you could use IsNumeric()
Code:
If Request("TypeName")="" Then
If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Elseif IsNumeric(Request("iType")) Then
' 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
Else
' display some message stating that the type id is not valid
End If
Or maybe you need to change the select statement to use the TypeName instead, just depends on what you want it to return. TypeID should never return more than 1 record, TypeName may return more than one depending on your data
Hi and thanks again for your reply........eeeerrrrmmmm yes.... it will take me a little while to digest that little gem but will try my best and let you know. It's all a little alien to me right now... sorry for being such a pain :blush:
-
Re: Error code help needed
Quote:
Originally Posted by
davida1956
Hi and thanks again for your reply........eeeerrrrmmmm yes.... it will take me a little while to digest that little gem but will try my best and let you know. It's all a little alien to me right now... sorry for being such a pain :blush:
Hi... I'm back again to bother you .... I tried what you suggested as shown below but it made no difference. When I add blank data as the category it doesn't trap it nor does it warn me so there is no error message. The data is however written to the database. When I try to edit it from the web console Explorer displays the message
/calendar/admin/category_edit.asp?iType=973 and displays ...error cannot display the page... Apart from this problem I have just about tweaked the code to do what I want, showing information I want, where I want and in the correct format and font
the database does however have a data Type field which does have the entry 973. This is what I modified. I'm not sure how to replace variable and what they should be. I know this is only a smallpart of the code, could there be something I am not including for you to pinpoint the problem perhaps?
[
<%
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>"
Elseif IsNumeric(Request("iType")) Then
' If Flag isn't true, show the edit form:
Dim CategoryRS
Else
Response.Write " You must enter a details for this to work"
' display some message stating that the type id is not valid
End If
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type WHERE TypeId =" & Request("iType"), Connect, 2, 3
End If
%>
]
I have a banging head now so will lay off for a few hours before going back again to tidy up some other details. I look forward to your reply ....Thanks :blush::wave:
-
Re: Error code help needed
Your If block is all messed up.
If TypeName="" Then
'code here will only execute if the typename is empty
End If
so if typename is not empty none of the code will execute will execute
I did not notice that second embedded If statement before not sure what its purpose is
Here I have commented out that If statement that tests flag. You should get different results
Code:
If Request("TypeName")="" Then
'If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Elseif IsNumeric(Request("iType")) Then
' 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
Else
' display some message stating that the type id is not valid
End If
Since I do not know what flag is or why you are testing for a blank name and then for flag I can't say how it should be to get your desired results but know that in your last post if typename not = "" then none of the following code will execute and will jump straight to the end if at the bottom
-
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
Your If block is all messed up.
If TypeName="" Then
'code here will only execute if the typename is empty
End If
so if typename is not empty none of the code will execute will execute
I did not notice that second embedded If statement before not sure what its purpose is
Here I have commented out that If statement that tests flag. You should get different results
Code:
If Request("TypeName")="" Then
'If Flag Then
Response.Write "<p class='subtitle'>You must enter a cateogry name.</p>"
Elseif IsNumeric(Request("iType")) Then
' 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
Else
' display some message stating that the type id is not valid
End If
Since I do not know what flag is or why you are testing for a blank name and then for flag I can't say how it should be to get your desired results but know that in your last post if typename not = "" then none of the following code will execute and will jump straight to the end if at the bottom
Thanks for your reply once again. I've got to give you 100% for trying to help and persevering with me my friend. I don't know if I can answer you questions fully but here goes. The project is a calendar system that I can use to display events through out the year. thy can be either single day evens or events that span a few weeks. I can add, delete or modify events without any problems. Part of the software allows me to create categories with associated colours that are displayed on the calendar page so for instance I could add new categories such as 'meetings', 'appointments' and holiday. When I add an event I can enter it under a category which is then displayed on the calendar day it is associated with. If I click on the event it will then provide me with all details I have entered when it was submitted. I should not be able to enter a new category without an associated name because it wouldn't make sense. I thought the code would check to make sure that I had given this new category a name and if not, reject the request with the error message. At the same time if I enter a valid category that meets with the conditions, it should advise me that the 'new' category has been added to the database. I'm not sure what all the variable do yet and if I can even trace them. I have posted the complete .asp file below just in case it helps you follow my thinking. You will obviously be able to make much more sense of it than me....
Code:
{
<% @EnableSessionState=True %>
<% Option Explicit %>
<%
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
%>
<% If Request.Cookies("AppLoggedIn") <> "True" Then Response.Redirect("default.asp")
If Request.Cookies("Admin") <> "True" Then Response.Redirect("default.asp") %>
<!--#include file="../Connections/conncalendarAdmin.asp" -->
<html>
<head>
<title>Calendar Admin Category Edit</title>
<link href="../assets/calendar.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body {
background-color: #30F;
margin-top: 50px;
}
</style>
</head>
<body>
<div align="center">
<table width="760" border="0" cellspacing="2" cellpadding="0">
<tr>
<td><div align="center">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#003399">
<tr>
<td bgcolor="#000">
<div class = "links">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="18" align="left" valign="middle" bgcolor="#FFE5B2" class="textBold"> <strong>
<a href="events.asp">EVENT LISTING</a> | <a href="submit.asp">ADD NEW EVENT</a> | <a href="purge.asp">PURGE OLD EVENTS</a> | <a href="category.asp">EDIT CATEGORIES</a></strong></td>
<td align="right" valign="middle" bgcolor="#FFE5B2" class="textBold"><div align="center"><A HREF="logout.asp"><strong>LOGOUT</strong></A> </div></td>
</tr>
</table>
</div>
<%
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>"
Elseif IsNumeric(Request("iType")) Then
' 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
Else
' display some message stating that the type id is not valid
Response.Write "<p class='subtitle'>I must have an error here somewhere...</p>"
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 align="left" valign="middle"><p> </p><form method="POST" action="<%= Request.ServerVariables("URL") %>" name="ADD">
<table align="center" class="textBold">
<tr valign="baseline">
<td nowrap align="right" valign="middle">EDIT CATEGORY NAME:</td>
<td> <input name="TypeName" type="text" class="form" value="<%=CategoryRS("TypeName")%>" size="50" maxlength="50">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="middle">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 nowrap align="right"> </td>
<td> <input name="Submit" type="submit" class="form" id="Submit" value="Submit">
</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
%></td>
</tr>
<tr>
<td align="center" valign="top"> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div></td>
</tr>
</table>
</div>
<div align="center"></div>
</body>
</html>
}
did it help any :confused: thanks one once again. you guys provide one hell of a service to the community....
-
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.
-
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
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.
Hello ....and many thanks once again for your reply.....I am a bit confused myself now :blush: The database is being updated successfully and the code does add or remove the appropriate information. I don't know if I am providing you with the correct information for you to help me resolve the issue ?? The code does NOT however report a blank entry, but it still adds one to the .mdb with ) value. Apart from that the rest of the code works fine. There is a comment in the software that shows the section of code that should detect the invalid entry but it doesn't work.:(
The other part of the process is advising me that the 'new category' I have just added has been added to the database and whilst it DOES add the new category with a 0 Value, it does NOT advice me that any record has been added to the database. I hope that makes sense? I do have 3 .asp forms... 1 displays all categories in the .mdb, 1 ADDS new categories to the .mdb and 1 allows me to EDIT categories that are present in the .mdb these all work.:confused:
Kind regards
David A
-
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?
-
Re: Error code help needed
Quote:
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...
-
Re: Error code help needed
Quote:
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
-
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.
-
Re: Error code help needed
Quote:
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.
-
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
Quote:
<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
Quote:
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.
-
Re: Error code help needed
Quote:
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
-
Re: Error code help needed
Quote:
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
-
Re: Error code help needed
Quote:
The only issue left is that it doesn't detect the " " String value
Quote:
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
-
Re: Error code help needed
Quote:
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?
-
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
Quote:
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.
-
Re: Error code help needed
Quote:
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 ..... :-)
-
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.
-
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
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.
Hi again..... soooo sorry but I am getting confused about what is where and seem to be going round in circles.... It may be that I have looked at it for so long I can't see the fault even if it jumped out at me.... frustrating ....yes! I modified this bit of code that I thought should do the job but again ... it doesn't. have you got any words of wisdom for me apart from 'go back to your hardware ' :-( I cant find any other code that may pass these details to the module for it to do the job
{
<%
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If trim (Request("TypeName"))="" Then
If Flag Then
Response.Write "<p class='subtitle'>You must enter a category 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
%>
Many thanks again ...
-
Re: Error code help needed
The code you just showed is not the code that adds to the database. That is just a select statement which will only execute if the If condition is false. From what you said before you want to stop the record from being added which you would need to do in the section where you add the record [the part I showed in my previous post. You just need to build your If clause in that block of code so that it does not execute the .AddNew and the .Update when you don;t want a record added.
-
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
The code you just showed is not the code that adds to the database. That is just a select statement which will only execute if the If condition is false. From what you said before you want to stop the record from being added which you would need to do in the section where you add the record [the part I showed in my previous post. You just need to build your If clause in that block of code so that it does not execute the .AddNew and the .Update when you don;t want a record added.
Hi again and many thanks for your patience. I'm really confused now and not sure at al what is doing what anymore. I know if I add a new category called NEW for instance, everything works fine and the software throws out 'The category "NEW" has been added to the database and it does add the category. I can't seem to get my head around why detecting that nothing has been entered for the category name. I have tried the trim as you suggested and as shown above, I've tried to comment out parts of the code as you suggested.... I think I got it right but I either get a 'page cannot be displayed' because I have introduced an error... or it affects other modules.
Everything seems to be linked together but one common error I get is with iType. This relates to a field n the db. If I check the .db though.. the field is there so what is it looking for, what am I missing...... I'm a full time job here aren't I :-( Am I trying to make it do something it was never designed to do perhaps? If the actual error message is there in code, is it not safe to assume the code has been written but that there is a fault? I'm not sure which way to turn now.... I do know I appreciate your help and whilst I am pretty good with my hardware I may never make a software engineer.
-
Re: Error code help needed
Look at where your If test is in the code.
Look at where the .AddNew is in the code
They are in different places and as a result your If test is not controlling the addnew. If you want the .AddNew controlled by an If test then you need an If test there as well.
Assuming I am understanding the issue here then the fix is simple
-
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
Look at where your If test is in the code.
Look at where the .AddNew is in the code
They are in different places and as a result your If test is not controlling the addnew. If you want the .AddNew controlled by an If test then you need an If test there as well.
Assuming I am understanding the issue here then the fix is simple
Hi again and many thanks for your reply. I know I have code in my category_edit.asp module and that it starts the process for detecting the error with the 'If' Sequence. This is the code...
{
<%
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If trim (Request("TypeName"))="" Then
If Flag Then
Response.Write "<p class='subtitle'>You must enter a category 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 code that performs the 'AddNew' is located in the module 'category_add.asp and the code for this is...
{
<%
' *** Insert new category, name and link color to the database:
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
%>
}
What I can't understand is where to put the additional 'If' statement nor how to define it. Does the software move between the two modules depending on the validity of the flag. As I mentioned, the only condition I want to check for is if the field which requests the name of a category does not have anything in it. I am using your idea of the trim which I presume I have inserted correctly so it should trap for an instance if just spaces are entered. It still does not throw out an error though in either instance. Can you perhaps show me how to add an 'If' statement where I have added *** in the code above assuming it is in the correct place ?? It may also help me correct an error which is supposed to display the category name and associated link colour that has been associated it though this is another issue. Thanks a million once again my friend.....,
-
Re: Error code help needed
Quote:
Originally Posted by
davida1956
Hi again and many thanks for your reply. I know I have code in my category_edit.asp module and that it starts the process for detecting the error with the 'If' Sequence. This is the code...
{
<%
Dim Flag, Query
' If the Category Name field is empty, and the form has been submitted:
If trim (Request("TypeName"))="" Then
If Flag Then
Response.Write "<p class='subtitle'>You must enter a category 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 code that performs the 'AddNew' is located in the module 'category_add.asp and the code for this is...
{
<%
' *** Insert new category, name and link color to the database:
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
%>
}
What I can't understand is where to put the additional 'If' statement nor how to define it. Does the software move between the two modules depending on the validity of the flag. As I mentioned, the only condition I want to check for is if the field which requests the name of a category does not have anything in it. I am using your idea of the trim which I presume I have inserted correctly so it should trap for an instance if just spaces are entered. It still does not throw out an error though in either instance. Can you perhaps show me how to add an 'If' statement where I have added *** in the code above assuming it is in the correct place ?? It may also help me correct an error which is supposed to display the category name and associated link colour that has been associated it though this is another issue. Thanks a million once again my friend.....,
Hi ..... I just thought I would add this other bit of code that may be associated with the problem because it doesn't seem to work either...
{
<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()
%>
}
I presume it outputs the message to the screen again ???
Regards
-
Re: Error code help needed
Quote:
Originally Posted by
davida1956
Hi ..... I just thought I would add this other bit of code that may be associated with the problem because it doesn't seem to work either...
{
<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()
%>
}
I presume it outputs the message to the screen again ???
Regards
Hi DataMiser... I haven't heard your words of wisdom for about a week and wondering if you are too busy to help or even if you are on holiday. perhaps jus fed up of me :-)Can you send me a sign please :-):blush::o
-
Re: Error code help needed
Why did you put those *s in there
Code:
<%
' *** Insert new category, name and link color to the database:
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
%>
Clearly if you want this code to add only when a given field has been populated with data then you would use an If test in this piece of code so that if the data exists in the given field it executes the code to add the data and if the data does not exist in the given field then you do not execute the code.
Code:
If Not Trim(MyTextBox.Text)="" Then
RS.Addnew
RS("Field1").Value=MyTextBox.Text
RS.Update
' show message that the record was added
Else
'show message that record can not be added or take some other action as needed
End IF
-
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
Why did you put those *s in there
Code:
<%
' *** Insert new category, name and link color to the database:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type", Connect, 2, 3
[COLOR="****[/COLOR]CategoryRS.AddNew [COLOR="*****[/COLOR]
CategoryRS("TypeName") = Request("TypeName")
CategoryRS("TypeColor") =Request("LinkColor")
CategoryRS.Update
%>
Clearly if you want this code to add only when a given field has been populated with data then you would use an If test in this piece of code so that if the data exists in the given field it executes the code to add the data and if the data does not exist in the given field then you do not execute the code.
Code:
If Not Trim(MyTextBox.Text)="" Then
RS.Addnew
RS("Field1").Value=MyTextBox.Text
RS.Update
[ ' show message that the record was added
Else
'show message that record can not be added or take some other action as needed
End IF
Hi there, pleased to hear back from you...phew... You hit the nail on the head and described exactly what I want to do and I added the *** to the code because I though that was where some sort of test needed to be made. Seems I got bit right at least but I didn't know how to construct an 'if' statement or what variables to use. I looked carefully at your code suggestions, figured out I still needed to declare the variable CategoryRS and set it as I have done. I then stuck in the IF test and... nothing :-(. I don't know if I am using the right variable you call value=MyTextBox which I assume is what is called 'TypeName' so I did the substitution. I know that if I add a valid category the code moves on, clears the screen and writes.... 'The category "New Test" has been added to the database.' which is perfect.
I have also found another problem with the code in so much as when you name a category and assign it a colour, it doesn't display the message included in the code advising you of the configuration ...i.e.. "You have added the category "new category" and assigned the colour "LinkColor" to it. That's another little thing I will have to look at. I wonder if the two are linked. I wish I was as good at writing code as I seen to be with fault finding it.. I did do that as part of my job for a while but never leant to write the darn stuff. Sooooo frustrating isn't it. I've copied my attempt at the new style code below and would be very grateful if you can tell me if I have gone wrong. I also show the part where the error message saying The "Category" has been successfully added to the database'' Not sure how your replies show the indents but will do it manually here if it will help. I have included but commented out the bits of code that used to be there just for ease really
[[/code}
<%
' *** Insert new category, name and link color to the database but allows it me to enter a blank field which it shouldn't ??:
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
If Not Trim("TypeName")=""Then
CategoryRS.Addnew
CategoryRS("TypeName").Value=Request("TypeName")
CategoryRS.Update
' This message is working and displayed a little further down in the code
Response.write ("The Category Has Been Added To The Database")
Else
' This error message cannot be seen and no code error is thrown out in browser
Response.write ("Value Not Added You must Enter A Valid Category Name")
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 align="center" valign="middle"><p class="textEvent"> </p>
<p class="textEvent">The category "
<% Response.Write Request("TypeName")
%>
" has been added to the database.</p>
<p class="textEvent"> </p></td>
[code}
Best Regards and really look forward to your reply.... Are you in the USA by any chance.. I happen to be stuck in the UK.
-
Re: Error code help needed
Quote:
Originally Posted by
davida1956
Hi there, pleased to hear back from you...phew... You hit the nail on the head and described exactly what I want to do and I added the *** to the code because I though that was where some sort of test needed to be made. Seems I got bit right at least but I didn't know how to construct an 'if' statement or what variables to use. I looked carefully at your code suggestions, figured out I still needed to declare the variable CategoryRS and set it as I have done. I then stuck in the IF test and... nothing :-(. I don't know if I am using the right variable you call value=MyTextBox which I assume is what is called 'TypeName' so I did the substitution. I know that if I add a valid category the code moves on, clears the screen and writes.... 'The category "New Test" has been added to the database.' which is perfect.
I have also found another problem with the code in so much as when you name a category and assign it a colour, it doesn't display the message included in the code advising you of the configuration ...i.e.. "You have added the category "new category" and assigned the colour "LinkColor" to it. That's another little thing I will have to look at. I wonder if the two are linked. I wish I was as good at writing code as I seen to be with fault finding it.. I did do that as part of my job for a while but never leant to write the darn stuff. Sooooo frustrating isn't it. I've copied my attempt at the new style code below and would be very grateful if you can tell me if I have gone wrong. I also show the part where the error message saying The "Category" has been successfully added to the database'' Not sure how your replies show the indents but will do it manually here if it will help. I have included but commented out the bits of code that used to be there just for ease really
[[/code}
<%
' *** Insert new category, name and link color to the database but allows it me to enter a blank field which it shouldn't ??:
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
If Not Trim("TypeName")=""Then
CategoryRS.Addnew
CategoryRS("TypeName").Value=Request("TypeName")
CategoryRS.Update
' This message is working and displayed a little further down in the code
Response.write ("The Category Has Been Added To The Database")
Else
' This error message cannot be seen and no code error is thrown out in browser
Response.write ("Value Not Added You must Enter A Valid Category Name")
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 align="center" valign="middle"><p class="textEvent">*</p>
<p class="textEvent">The category "
<% Response.Write Request("TypeName")
%>
" has been added to the database.</p>
<p class="textEvent">*</p></td>
[code}
Best Regards and really look forward to your reply.... Are you in the USA by any chance.. I happen to be stuck in the UK.
Well that didn't work dd it...
-
Re: Error code help needed
To get the proper indentation you need to use code tags
[code]
Your Code Here
[/code]
will give you
the spaces will be retained within the code tags.
-
Re: Error code help needed
Quote:
Originally Posted by
davida1956
Well that didn't work dd it...
Hi again.... told you I was a newbie.... never thought to read the screen... hopefully this works :-)
Code:
<%
' *** Insert new category, name and link color to the database but allows it me to enter a blank field which it shouldn't ??:
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
If Not Trim("TypeName")=""Then
CategoryRS.Addnew
CategoryRS("TypeName").Value=Request("TypeName")
CategoryRS.Update
'This message is working and displayed a little further down in the code
Response.write ("The Category Has Been Added To The Database")
Else
'This error message cannot be seen and no code error is thrown out in browser
Response.write ("Not Added You must Enter A Valid Category Name")
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 align="center" valign="middle"><p class="textEvent"> </p>
<p class="textEvent">The category "
<% Response.Write Request("TypeName")
%>
" has been added to the database.</p>
<p class="textEvent"> </p></td>
</tr>
Thanks a lot .......
-
Re: Error code help needed
This piece of code is going to execute no matter what the IF statement result was
Code:
<% Response.Write Request("TypeName")
%>
You want to write one of two messages depending on what your test did. If you want to do it where that line above is located then my advice would be to
1: Create a variable to hold the message.
2: set the variable to the message you want in the If portion and set it to the other message in the else portion
3: use the response.write line to write the variable that holds your message so it displays the proper message
Code:
Dim Msg
If Not Trim("TypeName")=""Then
CategoryRS.Addnew
CategoryRS("TypeName").Value=Request("TypeName")
CategoryRS.Update
'This message is working and displayed a little further down in the code
msg="The Category Has Been Added To The Database"
Else
'This error message cannot be seen and no code error is thrown out in browser
msg="Not Added You must Enter A Valid Category Name"
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 align="center" valign="middle"><p class="textEvent"> </p>
<p class="textEvent">
<% Response.Write msg
%>
</p>
-
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
This piece of code is going to execute no matter what the IF statement result was
[code]
<% Response.Write Request("TypeName")
%>
[code]
You want to write one of two messages depending on what your test did. If you want to do it where that line above is located then my advice would be to
1: Create a variable to hold the message.
2: set the variable to the message you want in the If portion and set it to the other message in the else portion
3: use the response.write line to write the variable that holds your message so it displays the proper message
Code:
Dim Msg
If Not Trim("TypeName")=""Then
CategoryRS.Addnew
CategoryRS("TypeName").Value=Request("TypeName")
CategoryRS.Update
'This message is working and displayed a little further down in the code
msg="The Category Has Been Added To The Database"
Else
'This error message cannot be seen and no code error is thrown out in browser
msg="Not Added You must Enter A Valid Category Name"
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 align="center" valign="middle"><p class="textEvent"> </p>
<p class="textEvent">
<% Response.Write msg
%>
</p>
Hi Again and thanks ever so much for your advice. You have made the explanation very easy for me to follow and I understand the logic now. I reconstructed the statement you showed me how to, with a little modification of my own that seems to work fine. If I add a category called 'Test' then it updates the database and shows the correct message the way I have asked it to a little further down in the code as shown. If I enter nothing or spaces then it doesn't trap it and still adds a blank name with zero records to the database with the message "" added to the database.
Could it be that the trim is for some reason not working? If no input is given it should throw out the request with the error message you have given in your example?? So it half works but then it always did.. its the ..... if I don't enter anything .... part that doesn't work and I cant understand why after giving me so much advice which I have tried to follow the condition still escapes. Everything seems to be logical and all there but still it evades me..... This is the code I have which is broadly in line with yours. Any further ideas my friend? would a link to the live site to see how it works online be of any help??
Code:
<%
' *** Insert new category, name and link color to the database but allows it me to enter a blank field which it shouldn't ??:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type", Connect, 2, 3
Dim Msg
If Not Trim("TypeName")=""Then
CategoryRS.Addnew
CategoryRS("TypeName").Value=Request("TypeName")
CategoryRS.Update
Else
Response.write ("You Hane Not Entered A Valid Category Name")
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 align="center" valign="middle"><p class="textEvent"> </p>
<p class="textEvent">The category "
<% Response.Write Request("TypeName")
%>
" has been added to the database.</p>
<p class="textEvent"> </p>
-
Re: Error code help needed
Separate the logic, and test!
Code:
Dim Flag as Boolean
Flag=FALSE
Dim Test as String
If Test = Trim("TypeName")="" Then Flag=TRUE
If Flag = TRUE then
' Add record only if true
End If
-
Re: Error code help needed
Quote:
Originally Posted by
dglienna
Separate the logic, and test!
Code:
Dim Flag as Boolean
Flag=FALSE
Dim Test as String
If Test = Trim("TypeName")="" Then Flag=TRUE
If Flag = TRUE then
' Add record only if true
End If
Hi There..... I've tried to do as you suggested but all l get is a blank webpage with error 500. I've copied the code below to see if you think I have made any errors ???
Code:
<%
' *** Insert new category, name and link color to the database but allows it me to enter a blank field which it shouldn't ??:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type", Connect, 2, 3
If Not Trim("TypeName")=""Then
'Else
' Response.write ("You Have Not Entered A Valid Category Name")
'End If
'Dim Flag as Boolean
'Flag=FALSE
'Dim Test as String
'If Test = Trim("TypeName")="" Then Flag=TRUE
'If Flag = TRUE then
' Add record only if true
CategoryRS.Addnew
CategoryRS("TypeName").Value=Request("TypeName")
CategoryRS.Update
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 align="center" valign="middle"><p class="textEvent"> </p>
<p class="textEvent">The category "
<% Response.Write Request("TypeName")
%>
" has been added to the database.</p>
<p class="textEvent"> </p>
all suggestions and help gratefully accepted..... Regards
-
Re: Error code help needed
Looks like you COMMENTED OUT all my code. Delete the '
IN EACH LINE at the BEGINNING of the LINE
-
Re: Error code help needed
Quote:
Originally Posted by
davida1956
Hi There..... I've tried to do as you suggested but all l get is a blank webpage with error 500. I've copied the code below to see if you think I have made any errors ???
Code:
<%
' *** Insert new category, name and link color to the database but allows it me to enter a blank field which it shouldn't ??:
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type", Connect, 2, 3
If Not Trim("TypeName")=""Then
'Else
' Response.write ("You Have Not Entered A Valid Category Name")
'End If
'Flag=FALSE
'Dim Test as String
'If Test = Trim("TypeName")="" Then Flag=TRUE
'If Flag = TRUE then
' Add record only if true
CategoryRS.Addnew
CategoryRS("TypeName").Value=Request("TypeName")
CategoryRS.Update
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 align="center" valign="middle"><p class="textEvent"> </p>
<p class="textEvent">The category "
<% Response.Write Request("TypeName")
%>
" has been added to the database.</p>
<p class="textEvent"> </p>
all suggestions and help gratefully accepted..... Regards
Hello and many thanks for getting back to me so quickly :-) I commented the code out because it didn't work and just returned a blank web page with error 500. I left it like that just for one of you Guru warriors to make sure that I hadn't made a stupid mistake. This is so frustrating... it seems such a simple thing in logic.... trap if the field 'TypeName' is empty or contains spaces, if so don't update the database and display the error message. I can see how your code would work but can't for the life of me see why it doesn't :-(
-
Re: Error code help needed
Not sure why I did not notice this before
Code:
If Not Trim("TypeName")=""Then
This will always be true because it is using a literal string. In other words it will never be empty. It will always be "TypeName"
You need to either assign a variable and test that or you need to use the Request("TypeName") as you have done here
Code:
CategoryRS("TypeName").Value=Request("TypeName")
Code:
If Not Trim(Request("TypeName"))=""Then
-
Re: Error code help needed
Quote:
Originally Posted by
DataMiser
Not sure why I did not notice this before
Code:
If Not Trim("TypeName")=""Then
This will always be true because it is using a literal string. In other words it will never be empty. It will always be "TypeName"
You need to either assign a variable and test that or you need to use the Request("TypeName") as you have done here
Code:
CategoryRS("TypeName").Value=Request("TypeName")
Code:
If Not Trim(Request("TypeName"))=""Then
Hello and once again many thanks for your reply. I guess I am totally lost now, despite all your help and advice it still doesn't work as expected. I have added the latest information into the code and still I cannot see an error message. There is one difference however.... If I fail to assign a new category name or leave it blank the code does NOT add it to the database now. It does however still tell me that it has added the new category "" to the database. So it knows the string is empty and blocks the update. Why Can I not see the error message ?? With all the changes made I am now left with a chunk of code that looks so simple it is hard to see how it cannot do anything but work every time. I've shown it below. Do you have any other advice my friend, I'm close to giving up on it now..... :-( Thanks for staying with me...
[code]
<%
' *** INSERT NEW CATEGORY NAME AND LINK COLOUR TO THE DATABASE ***
Dim CategoryRS
Set CategoryRS = Server.CreateObject("ADODB.Recordset")
CategoryRS.Open "SELECT * FROM Type", Connect, 2, 3
If Not Trim(Request("TypeName"))=""Then
CategoryRS.Addnew
CategoryRS("TypeName").Value=Request("TypeName")
CategoryRS.Update
Else
' *** THE ERROR MESSAGE BELOW CANNOT BE SEEN***
Response.write ("Please Enter A Valid Category Name")
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 align="center" valign="middle"><p class="textEvent"> </p>
' *** AND THE CODE MOVES TO THIS POINT ON ALL TESTS ***
<p class="textEvent">The New Category "
<% Response.Write Request("TypeName")
%>
" Has Been Added To The Database.</p>
<p class="textEvent"> </p></td>
</tr>
[CODE/]