/ Forside / Teknologi / Udvikling / ASP / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
ASP
#NavnPoint
smorch 9259
Harlekin 1866
molokyle 1040
Steffanst.. 758
gandalf 657
smilly 564
gibson 560
cumano 530
MouseKeep.. 480
10  Random 410
Pre-formatted text inserted into Acc DB
Fra : Brian H. Madsen - Pc~


Dato : 11-06-01 08:26

Hey there,

Sorry for writing in English fellas, but I'm missing the three vital Danish
letters and it's a pain to use the old-fashioned method of displaying those
three (e.g.. aa - oe - ae) constantly. So I seriously hope that we have a
few English speaking ASP'ers in this newsgroup.

Ok to get to the core of my problem.

I'm trying to insert a pre-formatted text string from a form text field so
that I can display it in a news scroller (JavaScript crossbrowser)..The
problem with this is that if a person makes a line break (hits ENTER/RETURN)
in the form text field I get a JavaScript 'Undefined Variable' instead of a
variable containing the text.

Without using line breaks I don't have any problems whatsoever..Could
possibly that my string format function is a bit wrong (see, this is where
I'll be needing help as I'm starting to feel slightly frustrated).

Below you can see a snippet of the code involved :

******ASP Inserts text into DB******
<%
FormValue = Request.form("strDailyMessage")

function ChkString(str)
If str = "" Then str = " "
str = replace(str, chr(13), "\n")
ChkString = str
End If
End Function

IdValue = 1

'DBPath = Server.MapPath( "Message.mdb" )
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath( "Message.mdb" )

lngSQLrs = "UPDATE Dailymessage SET Message = '" & ChkString(FormValue) &
"' WHERE MessageID = " & IdValue &";"
'response.write lngSQLrs
Set rs = Server.CreateObject("ADODB.Recordset")

rs.Open lngSQLrs, Con, 3, 3

Con.Close
Set Con = Nothing

Response.redirect("index.asp")
%>

******ASP reads text from DB and reverts VBS/ASP variable to Javascript
variable******
<%
DBPath = Server.MapPath( "Message.mdb" )
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & DBPath

strSQLQuery = "SELECT MessageID, Message FROM Dailymessage WHERE
MessageID = 1"

Set rs = Server.CreateObject( "ADODB.Recordset" )

rs.Open strSQLQuery, Con, 3, 3
%>

<script language="Javascript">
var news = "<%=Response.write(rs("Message"))%>";
</script>

<%
Con.close
set con = nothing
%>

The two above snippets are from two seperate files (inserting asp file and
reading asp file).

Could anybody give me a hand with this problem of mine ? oh, and feel free
to reply in danish as I do speak the language (see above explenation ;) )..

Thanks nevertheless

Brian



 
 
Asbjørn Ulsberg (11-06-2001)
Kommentar
Fra : Asbjørn Ulsberg


Dato : 11-06-01 09:04

"Brian H. Madsen - PcPlus Web Design" <brian@pluswebdesign.com.au> skrev:
> <script language="Javascript">
> var news = "<%=Response.write(rs("Message"))%>";
> </script>

Først vil jeg bare si at "=Response.Write" er smør på flesk.
Du kan utelate "Response.Write" med "=", altså skrevet:

<% =rs("Message") %>

eller helst:

<% =rs.Fields("Message") %>

"=" erstatter "Response.Write". Til problemet ditt:
Hvis du sjekker det som blir skrevet ut av "Message",
hva får du opp da? Funksjonen din "ChkString()" kan
ordnes litt på;

<%

Function ChkString(str)
If Len(str) = 0 Then str = " "
str = Replace(str, vbCrLf, "\n")
str = Replace(str, vbCr, "\n")
ChkString = str
End Function

%>

--
Mvh
Asbjørn Ulsberg
asbjorn@tigerstaden.no



Lars Hoffmann (11-06-2001)
Kommentar
Fra : Lars Hoffmann


Dato : 11-06-01 09:06

Brian H. Madsen - PcPlus Web Design wrote in >
> ******ASP Inserts text into DB******
> <%
> FormValue = Request.form("strDailyMessage")
>
> function ChkString(str)
> If str = "" Then str = " "
> str = replace(str, chr(13), "\n")

Proev at gemme strengen "as is" i Databasen og foerst erstatte chr(13) med
"\n" naar du henter teksten fra database. For god ordens skyld, boer du nok
ogsaa lige lave noget i stil med:

str = replace(str, "'", "''")

Saa undgaar du at brugeren kan oedelaegge din SQL saetning

> IdValue = 1
>
> 'DBPath = Server.MapPath( "Message.mdb" )
> Set Con = Server.CreateObject( "ADODB.Connection" )
> Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
> Server.MapPath( "Message.mdb" )

Hvorfor bruger du ikke:
Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & DBPath

> lngSQLrs = "UPDATE Dailymessage SET Message = '" & ChkString(FormValue) &
> "' WHERE MessageID = " & IdValue &";"
> 'response.write lngSQLrs
> Set rs = Server.CreateObject("ADODB.Recordset")
>
> rs.Open lngSQLrs, Con, 3, 3
>
> Con.Close
> Set Con = Nothing
>
> Response.redirect("index.asp")
> %>
>
> ******ASP reads text from DB and reverts VBS/ASP variable to Javascript
> variable******
> <%
> DBPath = Server.MapPath( "Message.mdb" )
> Set Con = Server.CreateObject( "ADODB.Connection" )
> Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & DBPath
>
> strSQLQuery = "SELECT MessageID, Message FROM Dailymessage WHERE
> MessageID = 1"
>
> Set rs = Server.CreateObject( "ADODB.Recordset" )
>
> rs.Open strSQLQuery, Con, 3, 3
> %>
>
> <script language="Javascript">
> var news = "<%=Response.write(rs("Message"))%>";

og det var saa her jeg ville bruge:

var news = "<%=replace(rs("Message"),chr(13),"\n")%>";

btw at bruge "<%=response.write" er som at gaa med seler og livrem paa samme
tid.


> </script>
>
> <%
> Con.close
> set con = nothing
> %>
>
> The two above snippets are from two seperate files (inserting asp file and
> reading asp file).
>
> Could anybody give me a hand with this problem of mine ? oh, and feel free
> to reply in danish as I do speak the language (see above explenation ;) )..

ok. Det er dog ikke saa slemt at skrive aa,ae,oe naar man vaenner sig til det.
Jeg bruger det tit, da jeg paa arbejdet kun har et spansk tastatur.

Best regards
/Lars

--
Dette indlæg er sendt fra http://www.html.dk
* Søg og læs i de danske nyhedsgrupper om webdesign
* Tutorials og artikler om webdesign på dansk

Brian H. Madsen - Pc~ (11-06-2001)
Kommentar
Fra : Brian H. Madsen - Pc~


Dato : 11-06-01 13:29

Great!!

Thanks for that fellas...And yeah I know that Response.write is unnecessary
but it's just a coding habit from back when I took up ASP at first. Old
habits are hard to let go once you get up in age...he heheh

But thanks for the replies, I'll probably use a little bit from each
solution, though to Lars I have to add that pre-formatting your
variables/text/etc...before inserting them into your databases, is an
absolute must if you're working with highly dynamic content. Also for speed
and efficiency (asp has never been fast, though faster than PERL/CGI) it's
definitely sound to pre-format as well. At least that's what I've worked
with for some time and what my own experience tells me.

*Lars - Jo, det er ikke saa svaert at skrive med aa, ae eller oe hvis man
blot kunne vaenne sig til det, men desvaere saa har jeg ikke saa
forfaerdelig mange muligheder for at skrive dansk da jeg for tiden bor i
Australien.

Ahh, on a side note...how do you fellas prefer to validate forms ? (since
this intranet i'm working on at the moment contains more than 200 forms i
need to see a few different ways of form validation - got my own way but as
the typical issues with coding, it's all about habits - might be that one of
you fellas had an easier way than mine - share some secrets ??)

Also, what do you think about PHP and PHP-GTK ??? Is it taking over or just
a passing fancy ?



Lars Hoffmann (11-06-2001)
Kommentar
Fra : Lars Hoffmann


Dato : 11-06-01 13:50

Brian H. Madsen - PcPlus Web Design wrote in
dk.edb.internet.webdesign.serverside.asp:
> Great!!
>

> But thanks for the replies, I'll probably use a little bit from each
> solution, though to Lars I have to add that pre-formatting your
> variables/text/etc...before inserting them into your databases, is an
> absolute must if you're working with highly dynamic content.

ok, hvis det virker er det jo kanon. Om man vil formattere texten foer eller
efter man indsaetter den i databasen, afhaenger vel ogsaa af hvor mange gange
man regner med at teksten bliver hentet fra DB'en i forhold til hvor mange
gange der skrives til den.

> *Lars - Jo, det er ikke saa svaert at skrive med aa, ae eller oe hvis man
> blot kunne vaenne sig til det, men desvaere saa har jeg ikke saa
> forfaerdelig mange muligheder for at skrive dansk da jeg for tiden bor i
> Australien.

Fjong med mig, du skriver bare paa det sprog der nu er mest behageligt for dig

> Ahh, on a side note...how do you fellas prefer to validate forms ? (since
> this intranet i'm working on at the moment contains more than 200 forms i
> need to see a few different ways of form validation - got my own way but as
> the typical issues with coding, it's all about habits - might be that one of
> you fellas had an easier way than mine - share some secrets ??)

Hvad mener du med hvordan? Hvis du taenker paa serverside vs. clientside, saa
kan clientside kun anbefales naar der er tale om et intranet hvor alle
maskiner med 100% sikkerhed bruger samme opsaetning, ellers er serverside at
fortraekke, paa trods af at det er langsommere. Jeg har som regel forms i til
at submitte til request.servervariables("SCRIPT_NAME"), Saaledes at jeg har
form, validering of andet i samme dokument. Det goer det lidt svaerrere at
arbejde med, men naar man bliver vandt til det, giver det bedre muligheder for
at optimere coden.

> Also, what do you think about PHP and PHP-GTK ??? Is it taking over or just
> a passing fancy ?

Jeg har ikke den store erfaring med PHP, men noget siger mig at det er kommet
for at blive, bl.a. p.g.a. gratis linuxservere. (kom PHP foer eller efter
ASP?)

Med venlig hilsen
Lars

--
Dette indlæg er sendt fra http://www.html.dk
* Søg og læs i de danske nyhedsgrupper om webdesign
* Tutorials og artikler om webdesign på dansk

Jakob Andersen (11-06-2001)
Kommentar
Fra : Jakob Andersen


Dato : 11-06-01 13:51

"Lars Hoffmann" <lars@hoffmann.ac> wrote in message
news:9g2ep7$6ri$1@sunsite.dk...
> Hvad mener du med hvordan? Hvis du taenker paa serverside vs. clientside,
saa
> kan clientside kun anbefales naar der er tale om et intranet hvor alle
> maskiner med 100% sikkerhed bruger samme opsaetning, ellers er serverside
at
> fortraekke, paa trods af at det er langsommere.

Lav det begge steder. Så kan du spare din server for belastning.

> Jeg har ikke den store erfaring med PHP, men noget siger mig at det er
kommet
> for at blive, bl.a. p.g.a. gratis linuxservere. (kom PHP foer eller efter
> ASP?)

PHP. Har hvis man spørger mig en noget rodet struktur. De tilføjer bare nye
funktioner konstant for at give flere muligheder. Hvis PHPudviklerne
fortsætter med samme hastighed bliver funktions biblioteket snart meget
uoverskueligt. Derfor kan jeg bedre lide ASPs mere objektorienterede
opbygning. Og når ASP.NET kommer i den færdige version skulle det også gerne
overhale PHP

--
Jakob Andersen
FAQ for webdesign gruppen på
<http://www.usenet.dk/oss/dk.edb.internet.webdesign>
"Det er rart at være vigtig, men det er vigtigere at være rar "



Asbjørn Ulsberg (11-06-2001)
Kommentar
Fra : Asbjørn Ulsberg


Dato : 11-06-01 14:18

"Jakob Andersen" <jakob@andersen.as> skrev:
> PHP. Har hvis man spørger mig en noget rodet struktur. De tilføjer
> bare nye funktioner konstant for at give flere muligheder. Hvis
> PHPudviklerne fortsætter med samme hastighed bliver funktions biblioteket
> snart meget uoverskueligt. Derfor kan jeg bedre lide ASPs mere
> objektorienterede opbygning. Og når ASP.NET kommer i den færdige
> ersion skulle det også gerne overhale PHP

Det er også hva jeg tror og mener!

--
Mvh
Asbjørn Ulsberg
asbjorn@tigerstaden.no



Jakob Andersen (11-06-2001)
Kommentar
Fra : Jakob Andersen


Dato : 11-06-01 15:12

"Asbjørn Ulsberg" <asbjorn@tigerstaden.no> wrote in message
news:9g2gel$nbi$1@taliesin.netcom.net.uk...
> Det er også hva jeg tror og mener!

Og indtil ASP.NET kommer kan vi jo udvikle i et Unix miljø med HTML-embedded
mod_perl .. det er for godt..

--
Jakob Andersen
FAQ for webdesign gruppen på
<http://www.usenet.dk/oss/dk.edb.internet.webdesign>
"Det er rart at være vigtig, men det er vigtigere at være rar "



Brian H. Madsen - Pc~ (13-06-2001)
Kommentar
Fra : Brian H. Madsen - Pc~


Dato : 13-06-01 05:10

Hey again, missed a few points made by the other fellas earlier....

Before setting up our own web host and ISP, I found it extremely hard to
find affordable AND reliable PHP supported hosting. I was at one point with
a Dutch company but communication between Australia and Holland was slow and
tedious.

Would any of you know of an international web host with PHP support (and
MySQL of course) ? Is there a host you could recommend ?

And as to the growing function-base of PHP, well...PHP still seems to be in
it's 'infant' stage with the speed their progressing. Though overall, I like
PHP...It seems that you do a lot less coding for the same outcome (might
again just be my coding habit with ASP) and PHP also has a lot of very
useful functions that would take quite a lot of coding with ASP if you
wanted to reach the same outcome. A british friend of mine created a PHP
login portal where he managed to create and dynamically alter the PHP used
to support this. To this day I still haven't figured out how he managed that
but I trust his word on it. Any of you fellas had any experience/exposure to
dynamic PHP content ?

Anyways, must daff off....working day...(again)

Brian



Brian H. Madsen - Pc~ (13-06-2001)
Kommentar
Fra : Brian H. Madsen - Pc~


Dato : 13-06-01 05:02

Sorry, forgot to mention that this is for an intranet where I can assure
that each machine has the exact same settings.

I would prefer the formatting to occur before inserting it into the
database, and preferably also server-sided, as I find it easier to
correct/edit codes afterwards. (coding habit, might not be the only way, but
that's how I do it).

Thanks nevertheless

Brian



Søg
Reklame
Statistik
Spørgsmål : 177555
Tips : 31968
Nyheder : 719565
Indlæg : 6408859
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste