-
June 23rd, 2013, 06:18 PM
#31
Re: Error code help needed
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 ...
-
June 24th, 2013, 12:26 AM
#32
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.
Always use [code][/code] tags when posting code.
-
June 24th, 2013, 09:06 PM
#33
Re: Error code help needed
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.
-
June 25th, 2013, 10:26 AM
#34
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
Always use [code][/code] tags when posting code.
-
June 26th, 2013, 01:11 PM
#35
Re: Error code help needed
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.....,
-
June 26th, 2013, 06:01 PM
#36
Re: Error code help needed
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
-
July 1st, 2013, 09:57 PM
#37
Re: Error code help needed
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 :-)
-
July 3rd, 2013, 09:49 AM
#38
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
Always use [code][/code] tags when posting code.
-
July 3rd, 2013, 07:47 PM
#39
Re: Error code help needed
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.
-
July 3rd, 2013, 07:48 PM
#40
Re: Error code help needed
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...
-
July 3rd, 2013, 10:26 PM
#41
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.
Always use [code][/code] tags when posting code.
-
July 4th, 2013, 05:49 AM
#42
Re: Error code help needed
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 .......
-
July 5th, 2013, 01:31 AM
#43
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>
Last edited by DataMiser; July 5th, 2013 at 01:34 AM.
Always use [code][/code] tags when posting code.
-
July 5th, 2013, 04:34 PM
#44
Re: Error code help needed
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>
-
July 6th, 2013, 01:05 PM
#45
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
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
|