After you change the code and run it let us know what you get within the “[ ]” including the brackets. Please just do a copy and paste so we can see exactly how you see it.
It looks like your problem is that the value getting passed into your function has no value at all. Thus, making your SQL syntax invalid.
You need to have more error trapping on your page. Here is a little that you can start to play with.
Change your code to be this:
[code=asp]
Function SetCurrentPub(P ubID)
OpenDB
Set rs=Server.Creat eObject("ADODB. Recordset")
strSQL = "SELECT * FROM tblPublications WHERE PubID = " & PUBID
rs.Open strSQL, conn
If (rs.EOF) Then
Response.Write( "No records returned from the database!")
Response.End
End If
Lines 7 through 10 is checking to see if any records have been returned from the database based on your query. If no records then print something on the screen and stop processing. You can extend this more to your needs.
It looks like your problem is that the value getting passed into your function has no value at all. Thus, making your SQL syntax invalid.
You need to have more error trapping on your page. Here is a little that you can start to play with.
Change your code to be this:
[code=asp]
Function SetCurrentPub(P ubID)
OpenDB
Set rs=Server.Creat eObject("ADODB. Recordset")
strSQL = "SELECT * FROM tblPublications WHERE PubID = " & PUBID
rs.Open strSQL, conn
If (rs.EOF) Then
Response.Write( "No records returned from the database!")
Response.End
End If
Lines 7 through 10 is checking to see if any records have been returned from the database based on your query. If no records then print something on the screen and stop processing. You can extend this more to your needs.
Hope that helps~
I will give it a go see what happens, and let you know. I was assured that all these asp scripts I have inherited worked as were, and was told it was merely a case of changing paths to the database, but it looks like I've recieved a bag of worms!
Thanks for all your help, hope you'll be around a while longer.
“Response” is an object that is used to send output to the user from the server.
“Write” and “End” are both methods that are used within the object.
When we use “Response.Write ” in our code is when we want to paint something on to the screen. Example is Response.Write( “Hello World”) Any string value within the brackets will get painted on the screen. In this case the two words Hello World would get painted. We also can build a string value with in the brackets like this; Response.Write( “Hello World” & “ How are you?”) this would paint Hello World How are you? on the screen. We can also build a string out of variables too like this Response.Write( MyVariable) if the value of MyVariable was MyVariable=”Cod ing is fun” then Coding is fun would get painted on the screen.
When we use “Response.End” in our code is when we don’t want any more code to be processed. “Response.End” will stop the processing of a script at that point.
I had you put these two lines
[code=asp]
Response.Write( "[" & strSQL & "]")
Response.End
[/code]
in your code so I could verify that the value of “PUBID” was getting passed in to your function. How I determined this is because I had you paint/write out the value for the string “strSQL”. If the local variable “PUBID” had a value we would have seen it painted on the screen with the rest of your query.
Bottom line is somewhere on your page there is a line that is calling your function and not passing in a value for “PUBID”. Also, you should places more conditional/error trapping on your page. You will understand more on why you should probably after you’re done with your project.
Still, we are here to help you so post questions whenever you need help. Just try not to bleed multiple questions into one post. That way you will get answers faster and people tend to hate reading long threads.
“Response” is an object that is used to send output to the user from the server.
“Write” and “End” are both methods that are used within the object.
When we use “Response.Write ” in our code is when we want to paint something on to the screen. Example is Response.Write( “Hello World”) Any string value within the brackets will get painted on the screen. In this case the two words Hello World would get painted. We also can build a string value with in the brackets like this; Response.Write( “Hello World” & “ How are you?”) this would paint Hello World How are you? on the screen. We can also build a string out of variables too like this Response.Write( MyVariable) if the value of MyVariable was MyVariable=”Cod ing is fun” then Coding is fun would get painted on the screen.
When we use “Response.End” in our code is when we don’t want any more code to be processed. “Response.End” will stop the processing of a script at that point.
I had you put these two lines
[code=asp]
Response.Write( "[" & strSQL & "]")
Response.End
[/code]
in your code so I could verify that the value of “PUBID” was getting passed in to your function. How I determined this is because I had you paint/write out the value for the string “strSQL”. If the local variable “PUBID” had a value we would have seen it painted on the screen with the rest of your query.
Bottom line is somewhere on your page there is a line that is calling your function and not passing in a value for “PUBID”. Also, you should places more conditional/error trapping on your page. You will understand more on why you should probably after you’re done with your project.
Still, we are here to help you so post questions whenever you need help. Just try not to bleed multiple questions into one post. That way you will get answers faster and people tend to hate reading long threads.
Good luck and happy coding~
Thanks for that, trying to find the function that should pass the PUBID value, I have checked the paths and they all seem fine, any ideas?
I would do a “search” for the word “SetCurrentPub” with the text editor that you’re using. If you can’t find it start checking all of the include files too.
Now when you do find it use the Response.Write on the variable that is getting passing to see if has a value.
Welcome to the wonderful world of debugging someone else’s code.
Comment