|
 |
asp_databases thread: Inserting links and pictures to fields, but how?
Message #1 by "Marko Ramstedt" <marko.ramstedt@a...> on Sun, 25 Aug 2002 15:48:43
|
|
I'm trying to insert a link of a picture and it should be the same
as the username. Like "user33.jpg". Here is the code so far:
--------------------------------------------------------------------
<%
Dim spicture
Dim sSql4
Dim Conn4
Dim ConnStr4
Set conn = Server.CreateObject("ADODB.Connection")
connStr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("/data/users_fin.mdb")
Conn.Open connStr
sSql = "SELECT * FROM Users WHERE UserName = '" & Request.Form
("txtUsername") & "' "
Set StrRS = Server.CreateObject("ADODB.Recordset")
StrRS.Open sSql,Conn
Do While Not StrRS.EOF
sUsername = Request.Form("txtUsername")
spicture = "<a href="/dev/images/'" & sUsername & "'.jpg"><img
src="/dev/images/camera.gif"></a>"
StrRS.MoveNext
Loop
StrRS.Close
Conn.Close
Set StrRS=Nothing
Set Conn=Nothing
Set conn4 = Server.CreateObject("ADODB.Connection")
ConnStr4 = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("/data/users_fin.mdb")
Conn4.Open connStr
sSql4="Update Users Set Picture = '" & spicture & "' WHERE UserName = '"
& sUsername & "' "
Conn4.Execute sSql4
Conn4.Close
Set Conn4=Nothing
%>
--------------------------------------------------
Error:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/dev/services/activate2.asp, line 43, column 33
spicture = "<a href="/dev/images/'" & sUsername & "'.jpg"><img
src="/dev/images/camera.gif"></a>"
--------------------------------^
Message #2 by "Kim Iwan Hansen" <kimiwan@k...> on Sun, 25 Aug 2002 22:24:00 +0200
|
|
When you read the string given in the error from a machine's point of view,
it looks like this:
Assign the following string to spicture
Begin string
<a href
End string
/dev/images'...
When want to put a double quote in a string, you have to use two of them,
like this: (watch wrapping)
spicture = "<a href=""/dev/images'" & sUsername & "'.jpg""><img
src=""/dev/images/camera.gif""></a>"
See the difference? Think like a machine when you go through your code with
errors, that'll get you far :o)
-Kim
> Error:
>
> Microsoft VBScript compilation (0x800A03EA)
> Syntax error
>
> /dev/services/activate2.asp, line 43, column 33
> spicture = "<a href="/dev/images/'" & sUsername & "'.jpg"><img
> src="/dev/images/camera.gif"></a>"
> --------------------------------^
Message #3 by "Marko Ramstedt" <marko.ramstedt@a...> on Sun, 25 Aug 2002 22:25:04
|
|
Thank you so much, you saved my day :-))
> When you read the string given in the error from a machine's point of
view,
it looks like this:
Assign the following string to spicture
Begin string
<a href
End string
/dev/images'...
When want to put a double quote in a string, you have to use two of them,
like this: (watch wrapping)
spicture = "<a href=""/dev/images'" & sUsername & "'.jpg""><img
src=""/dev/images/camera.gif""></a>"
See the difference? Think like a machine when you go through your code
with
errors, that'll get you far :o)
-Kim
> Error:
>
> Microsoft VBScript compilation (0x800A03EA)
> Syntax error
>
> /dev/services/activate2.asp, line 43, column 33
> spicture = "<a href="/dev/images/'" & sUsername & "'.jpg"><img
> src="/dev/images/camera.gif"></a>"
> --------------------------------^
Message #4 by "Marko Ramstedt" <marko.ramstedt@a...> on Tue, 27 Aug 2002 11:36:21
|
|
Last one worked, but how will I get this inserted to the field?
<a href="#" onClick="MyWindow=window.open
('http://www.yahoo.com','MyWindow','toolbar=no,location=no,directories=no,
status=no,menubar=no,scrollbars=no,resizable=no,width=320,height=240,left
170,top=170'); return false;"><img src="/dev/images/camera.gif"</a>
I've tried " "" """ ' '' and many combinations of these.
-Marko
> I'm trying to insert a link of a picture and it should be the same
a> s the username. Like "user33.jpg". Here is the code so far:
> --------------------------------------------------------------------
> <%
> Dim spicture
D> im sSql4
D> im Conn4
D> im ConnStr4
> Set conn = Server.CreateObject("ADODB.Connection")
> connStr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
S> erver.MapPath("/data/users_fin.mdb")
C> onn.Open connStr
> sSql = "SELECT * FROM Users WHERE UserName = '" & Request.Form
(> "txtUsername") & "' "
> Set StrRS = Server.CreateObject("ADODB.Recordset")
S> trRS.Open sSql,Conn
> Do While Not StrRS.EOF
> sUsername = Request.Form("txtUsername")
> spicture = "<a href="/dev/images/'" & sUsername & "'.jpg"><img
s> rc="/dev/images/camera.gif"></a>"
> StrRS.MoveNext
L> oop
>
S> trRS.Close
C> onn.Close
>
S> et StrRS=Nothing
S> et Conn=Nothing
> Set conn4 = Server.CreateObject("ADODB.Connection")
C> onnStr4 = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
S> erver.MapPath("/data/users_fin.mdb")
C> onn4.Open connStr
> sSql4="Update Users Set Picture = '" & spicture & "' WHERE UserName
= '"
&> sUsername & "' "
> Conn4.Execute sSql4
C> onn4.Close
S> et Conn4=Nothing
> %>
> --------------------------------------------------
> Error:
> Microsoft VBScript compilation (0x800A03EA)
S> yntax error
> /dev/services/activate2.asp, line 43, column 33
s> picture = "<a href="/dev/images/'" & sUsername & "'.jpg"><img
s> rc="/dev/images/camera.gif"></a>"
-> -------------------------------^
Message #5 by "Kim Iwan Hansen" <kimiwan@k...> on Tue, 27 Aug 2002 12:42:25 +0200
|
|
You're not closing your img tag.
An easy way to get around the double quote issue is to write the html you
need, then replace " with "" and THEN insert the variables where you need
them.
Focus on one thing at a time, make sure you got the string right before you
move on to the next step.
-Kim
> -----Original Message-----
> From: Marko Ramstedt [mailto:marko.ramstedt@a...]
> Sent: 27. august 2002 11:36
> To: ASP Databases
> Subject: [asp_databases] Re: Inserting links and pictures to fields, but
> how?
>
>
> Last one worked, but how will I get this inserted to the field?
>
> <a href="#" onClick="MyWindow=window.open
> ('http://www.yahoo.com','MyWindow','toolbar=no,location=no,directories=no,
> status=no,menubar=no,scrollbars=no,resizable=no,width=320,height=240,left
> 170,top=170'); return false;"><img src="/dev/images/camera.gif"</a>
>
> I've tried " "" """ ' '' and many combinations of these.
>
> -Marko
>
>
>
> > I'm trying to insert a link of a picture and it should be the same
> a> s the username. Like "user33.jpg". Here is the code so far:
>
> > --------------------------------------------------------------------
>
> > <%
>
> > Dim spicture
> D> im sSql4
> D> im Conn4
> D> im ConnStr4
>
> > Set conn = Server.CreateObject("ADODB.Connection")
>
> > connStr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
> S> erver.MapPath("/data/users_fin.mdb")
> C> onn.Open connStr
>
> > sSql = "SELECT * FROM Users WHERE UserName = '" & Request.Form
> (> "txtUsername") & "' "
>
> > Set StrRS = Server.CreateObject("ADODB.Recordset")
> S> trRS.Open sSql,Conn
>
> > Do While Not StrRS.EOF
>
> > sUsername = Request.Form("txtUsername")
>
> > spicture = "<a href="/dev/images/'" & sUsername & "'.jpg"><img
> s> rc="/dev/images/camera.gif"></a>"
>
> > StrRS.MoveNext
> L> oop
> >
> S> trRS.Close
> C> onn.Close
> >
> S> et StrRS=Nothing
> S> et Conn=Nothing
>
> > Set conn4 = Server.CreateObject("ADODB.Connection")
> C> onnStr4 = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
> S> erver.MapPath("/data/users_fin.mdb")
> C> onn4.Open connStr
>
> > sSql4="Update Users Set Picture = '" & spicture & "' WHERE UserName
> = '"
> &> sUsername & "' "
>
> > Conn4.Execute sSql4
> C> onn4.Close
> S> et Conn4=Nothing
>
> > %>
>
> > --------------------------------------------------
>
> > Error:
>
> > Microsoft VBScript compilation (0x800A03EA)
> S> yntax error
>
> > /dev/services/activate2.asp, line 43, column 33
> s> picture = "<a href="/dev/images/'" & sUsername & "'.jpg"><img
> s> rc="/dev/images/camera.gif"></a>"
> -> -------------------------------^
>
Message #6 by "Drew, Ron" <RDrew@B...> on Tue, 27 Aug 2002 08:27:50 -0400
|
|
From MyWindow to ; is one line...
<SCRIPT LANGUAGE=3D"JavaScript">
<!--
function popWindow() {
MyWindow=3Dwindow.open('http://www.yahoo.com','MyWindow','toolbar=3Dno,lo
cat
ion=3Dno,directories=3Dno,status=3Dno,menubar=3Dno,scrollbars=3Dno,resiza
ble=3Dno,wi
dth=3D320,height=3D240,left=3D170,top=3D170');
}
//-->
</SCRIPT>
This is how the function gets activated:
<a href=3D"javascript:popWindow()">Click here for Yahoo.<img
src=3D"/dev/images/camera.gif"</a>
-----Original Message-----
From: Marko Ramstedt [mailto:marko.ramstedt@a...]
Sent: Tuesday, August 27, 2002 7:36 AM
To: ASP Databases
Subject: [asp_databases] Re: Inserting links and pictures to fields, but
how?
Last one worked, but how will I get this inserted to the field?
<a href=3D"#" onClick=3D"MyWindow=3Dwindow.open
('http://www.yahoo.com','MyWindow','toolbar=3Dno,location=3Dno,directorie
s=3Dn
o,
status=3Dno,menubar=3Dno,scrollbars=3Dno,resizable=3Dno,width=3D320,heigh
t=3D240,lef
t=3D
170,top=3D170'); return false;"><img src=3D"/dev/images/camera.gif"</a>
I've tried " "" """ ' '' and many combinations of these.
-Marko
> I'm trying to insert a link of a picture and it should be the same
a> s the username. Like "user33.jpg". Here is the code so far:
> --------------------------------------------------------------------
> <%
> Dim spicture
D> im sSql4
D> im Conn4
D> im ConnStr4
> Set conn =3D Server.CreateObject("ADODB.Connection")
> connStr =3D "DRIVER=3D{Microsoft Access Driver (*.mdb)}; DBQ=3D" &
S> erver.MapPath("/data/users_fin.mdb")
C> onn.Open connStr
> sSql =3D "SELECT * FROM Users WHERE UserName =3D '" & Request.Form
(> "txtUsername") & "' "
> Set StrRS =3D Server.CreateObject("ADODB.Recordset")
S> trRS.Open sSql,Conn
> Do While Not StrRS.EOF
> sUsername =3D Request.Form("txtUsername")
> spicture =3D "<a href=3D"/dev/images/'" & sUsername & "'.jpg"><img
s> rc=3D"/dev/images/camera.gif"></a>"
> StrRS.MoveNext
L> oop
>
S> trRS.Close
C> onn.Close
>
S> et StrRS=3DNothing
S> et Conn=3DNothing
> Set conn4 =3D Server.CreateObject("ADODB.Connection")
C> onnStr4 =3D "DRIVER=3D{Microsoft Access Driver (*.mdb)}; DBQ=3D" &
S> erver.MapPath("/data/users_fin.mdb")
C> onn4.Open connStr
> sSql4=3D"Update Users Set Picture =3D '" & spicture & "' WHERE
UserName
=3D '"
&> sUsername & "' "
> Conn4.Execute sSql4
C> onn4.Close
S> et Conn4=3DNothing
> %>
> --------------------------------------------------
> Error:
> Microsoft VBScript compilation (0x800A03EA)
S> yntax error
> /dev/services/activate2.asp, line 43, column 33
s> picture =3D "<a href=3D"/dev/images/'" & sUsername & "'.jpg"><img
s> rc=3D"/dev/images/camera.gif"></a>"
-> -------------------------------^
Message #7 by "Marko Ramstedt" <marko.ramstedt@a...> on Tue, 27 Aug 2002 15:26:28
|
|
Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/dev/services/activate3.asp, line 51, column 35
sPicture = "<a href=""#"" onClick="MyWindow=window.open
('http://localhost/dev/images/" & sID & ".jpg','MyWindow" & sID
& "','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollba
rs=yes,resizable=yes,width=320,height=240,left=170,top=170'); return
false;""><img src=""/dev/images/camera.gif""></a>"
----------------------------------^
Message #8 by "Marko Ramstedt" <marko.ramstedt@a...> on Tue, 27 Aug 2002 15:32:38
|
|
This line:
sPicture = "<a href=""#"" onClick="MyWindow=window.open
('http://localhost/dev/images/" & sID & ".jpg','MyWindow" & sID
& "','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollba
rs=yes,resizable=yes,width=320,height=240,left=170,top=170'); return
false;""><img src=""/dev/images/camera.gif""></a>"
Gives this error:
Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/dev/services/activate3.asp, line 51, column 35
sPicture = "<a href=""#"" onClick="MyWindow=window.open
('http://localhost/dev/images/" & sID & ".jpg','MyWindow" & sID
& "','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollba
rs=yes,resizable=yes,width=320,height=240,left=170,top=170'); return
false;""><img src=""/dev/images/camera.gif""></a>"
----------------------------------^
This one works though fine:
sPicture = "<a href=""/dev/aspupload/uploads/images" & sID & ".jpg""><img
src=""/dev/images/camera.gif""></a>"
But I would want to use some better way to open the images and not
a whole window, because the pics are so small 320x240 :-)
Message #9 by "Peter Foti (PeterF)" <PeterF@S...> on Tue, 27 Aug 2002 10:30:52 -0400
|
|
You are missing a double quotes around the onClick value. Try this:
sPicture = "<a href=""#""
onClick=""MyWindow=window.open('http://localhost/dev/images/" & sID &
".jpg','MyWindow" & sID &
"','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=y
es,resizable=yes,width=320,height=240,left=170,top=170'); return
false;""><img src=""/dev/images/camera.gif""></a>"
> -----Original Message-----
> From: Marko Ramstedt [mailto:marko.ramstedt@a...]
> Sent: Tuesday, August 27, 2002 3:26 PM
> To: ASP Databases
> Subject: [asp_databases] Re: Inserting links and pictures to
> fields, but
> how?
>
>
> Error Type:
> Microsoft VBScript compilation (0x800A0401)
> Expected end of statement
> /dev/services/activate3.asp, line 51, column 35
> sPicture = "<a href=""#"" onClick="MyWindow=window.open
> ('http://localhost/dev/images/" & sID & ".jpg','MyWindow" & sID
> &
> "','toolbar=no,location=no,directories=no,status=yes,menubar=n
> o,scrollba
> rs=yes,resizable=yes,width=320,height=240,left=170,top=170'); return
> false;""><img src=""/dev/images/camera.gif""></a>"
> ----------------------------------^
>
Message #10 by "Marko Ramstedt" <marko.ramstedt@a...> on Tue, 27 Aug 2002 18:47:21
|
|
I inserted the code but it backfires :-(
sPicture = "<a href=""#"" onClick=""MyWindow=window.open
('http://localhost/dev/images/" & sID &".jpg','MyWindow" & sID
& "','toolbar=no,location=yes,directories=no,status=yes,menubar=no,scrollb
ars=no,resizable=no,width=320,height=240,left=170,top=170'); return
false;""><img src=""/dev/images/camera.gif""></a>"
-------------------------------------------------------------------------
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator)
in query expression ''<a href="#" onClick="MyWindow=window.open
('http://localhost/dev/images/2129.jpg','MyWindow2129','toolbar=no'.
/dev/services/activate2.asp, line 78
What is wrong this time??????????????????
Message #11 by "Brent VanderMeide" <ccbbttmm@a...> on Tue, 27 Aug 2002 20:33:56
|
|
Marko,
' This line is now correct
sPicture = "<a href=""#"" onClick=""MyWindow=window.open
('http://localhost/dev/images/" & sID &".jpg','MyWindow" & sID
& "','toolbar=no,location=yes,directories=no,status=yes,menubar=no,scrollb
ars=no,resizable=no,width=320,height=240,left=170,top=170'); return
false;""><img src=""/dev/images/camera.gif""></a>"
What is it you are trying to do now? What is the code of line that is
giving you the error.?
I believe I know what is causing this issue which seems to be a database
INSERT / UPDATE error because your sPicture variable now has (')'s in it.
give me your section of code that is giving you this error.
Message #12 by "Peter Foti (PeterF)" <PeterF@S...> on Tue, 27 Aug 2002 16:00:04 -0400
|
|
Backfires how? I'll try writing this out across several lines to see if
another problem becomes more aparent:
sPicture = "<a href=""#"" onClick=""" & _
"MyWindow=window.open(" & _
"'http://localhost/dev/images/" & sID & ".jpg'," & _
"'MyWindow" & sID & "'," & _
"'toolbar=no,location=yes,directories=no,status=yes," & _
"menubar=no,scrollbars=no,resizable=no,width=320,height=240," & _
"left=170,top=170'); return false;"">" & _
"<img src=""/dev/images/camera.gif""></a>"
Nope, I don't see anything wrong. And putting this into an ASP file where
sID = "foobar" and then doing response.write on sPicture will yield the
following results:
<a href="#"
onClick="MyWindow=window.open('http://localhost/dev/images/foobar.jpg','MyWi
ndowfoobar','toolbar=no,location=yes,directories=no,status=yes,menubar=no,sc
rollbars=no,resizable=no,width=320,height=240,left=170,top=170'); return
false;"><img src="/dev/images/camera.gif"></a>
> -----Original Message-----
> From: Marko Ramstedt [mailto:marko.ramstedt@a...]
> Sent: Tuesday, August 27, 2002 6:47 PM
> To: ASP Databases
> Subject: [asp_databases] Re: Inserting links and pictures to fields, b
> ut how?
>
>
> I inserted the code but it backfires :-(
>
> sPicture = "<a href=""#"" onClick=""MyWindow=window.open
> ('http://localhost/dev/images/" & sID &".jpg','MyWindow" & sID
> &
> "','toolbar=no,location=yes,directories=no,status=yes,menubar
> no,scrollb
> ars=no,resizable=no,width=320,height=240,left=170,top=170'); return
> false;""><img src=""/dev/images/camera.gif""></a>"
>
> --------------------------------------------------------------
> -----------
>
> Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
>
> [Microsoft][ODBC Microsoft Access Driver] Syntax error
> (missing operator)
> in query expression ''<a href="#" onClick="MyWindow=window.open
> ('http://localhost/dev/images/2129.jpg','MyWindow2129','toolbar=no'.
>
> /dev/services/activate2.asp, line 78
>
> What is wrong this time??????????????????
>
Message #13 by "Marko Ramstedt" <marko.ramstedt@a...> on Wed, 28 Aug 2002 06:23:19
|
|
Yes, you are propably right...
How can I change it?
Here is the complete code:
<%
Dim sSql2
Dim Conn2
Dim ConnStr2
Dim ID
Dim sID
Dim sUsername
Dim sPicture
Set conn2 = Server.CreateObject("ADODB.Connection")
ConnStr2 = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("/data/users_fin.mdb")
Conn2.Open connStr2
sPicture = "<a href=""#"" onClick=""MyWindow=window.open
('http://localhost/dev/images/" & sID &".jpg','MyWindow" & sID
& "','toolbar=no,location=yes,directories=no,status=yes,menubar=no,scrollb
ars=no,resizable=no,width=320,height=240,left=170,top=170');""><img
src=""/dev/images/camera.gif""></a>"
sSql2="Update Users Set Picture = '" & sPicture & "' WHERE UserName = '"
& sUsername & "' "
Conn2.Execute sSql2
Conn2.Close
Set Conn2=Nothing
%>
Message #14 by "the Office of Brent Allen VanderMeide" <ccbbttmm@a...> on Wed, 28 Aug 2002 13:18:22 -0600
|
|
Excellent,
Here you go,
The main problem of your code is that the sPicture now
______________________________________________________
<a href="#" onClick="MyWindow=window.open
('http://localhost/dev/images/1001.jpg','MyWindow1001','toolbar=no,locat
ion=yes,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,
width=320,height=240,left=170,top=170');"><img
src="/dev/images/camera.gif"></a>
______________________________________________________
I'm not sure if what you want in your database is this, but the reason
why you are having a syntax error is that your sPicture string now
contains apostrophes inside of it. Like VBScript uses Quotation marks
for strings, SQL query language uses apostrophes('). So now that you
are taking this long string into your SQL query/update, we will need to
convert it to SQL ready.
'YOU WROTE THIS LINE IN YOUR CODE
'**********************************************
sSql2="Update Users Set Picture = '" & sPicture & "' WHERE UserName = '"
& sUsername & "' "
'CHANGE IT TO THIS
'**********************************************
sSql2="Update Users Set Picture = '" & replace(sPicture, "'", "''") & "'
WHERE UserName = '" & sUsername & "' "
Congratulations,
Issue resolved. However; I would not recommend that you insert the
actual HTML link in the database. I would simply insert the virtual
path in the database such as, "/dev/images/1001.jpg". This way you will
not need to filter out the HTML code for future use.
You may want to use two fields. One that provides the Image Filename,
"1001.jpg", and another that provides the virtual path, "/dev/images".
Picture VPath
_____________________ ________________________
1001.jpg /dev/images
Anyhow, good luck. Please let me know if this helps, and if you need
further help.
Thank you,
Brent Allen VanderMeide
Intermountain Software Solutions
Senior Web & Application Developer
brent@s...
|
|
 |