Avatar billede guzzie Nybegynder
27. februar 2001 - 09:04 Der er 17 kommentarer og
1 løsning

check box again :)

hey there

I have a check box that i use in my database
I have with the help of eksperten got it to work on my asp page where it only shows those news items that are set to True.
so far so good :)
However now I need a little more help :P
I have another asp page that inserts into a database
heres the db connection now
<%
Response.Buffer = True
FUNCTION fixQuotes( theString )
    fixQuotes = Replace( theString, \"\'\", \"\'\'\" )
END FUNCTION
    news_name = Request( \"news_name\" )
    news = Request( \"news\" )
    authour = Request( \"authour\" )
    email = Request( \"email\" )
    publish = Request( \"publish\" )
Set Con = Server.CreateObject( \"ADODB.Connection\" )
    DBPath = \"DBQ=\" & server.mappath(\"../media.mdb\")
    Con.Open \"DRIVER={Microsoft Access Driver (*.mdb)}; \" & DBPath
IF Request.Servervariables(\"Content_Length\") > 0 THEN
    Sql = \"INSERT INTO news (dato, news_name, news, authour, email, publish) VALUES(\'\" & Date() & \"\',\'\" & fixQuotes( news_name ) & \"\',\'\" & fixQuotes( news ) & \"\',\'\" & fixQuotes( authour ) & \"\',\'\" & fixQuotes( email ) & \"\',\'\" & fixQuotes( publish ) & \"\')\"
    Con.Execute Sql
    Response.Write \"<table valign=top align=center width=750 cellpadding=5 cellspacing=0><tr><td align=center id=td_noborder_color><b><font size=3 color=red>Nyheden er nu tilføjt til databasen</font></b></td></tr></table>\"

END IF

%>
publish is a checkbox
and the form I use also has a checkbox called publish blah blah blah ....
But what i was wondering is this
how should my Sql look or what syntax should I use with publish
Any ideas would as usual me welcome
Guzzie
Avatar billede eagleeye Praktikant
27. februar 2001 - 09:25 #1
You dont need \'\' around publish.
It should be &  publish
NOT: & fixQuotes( publish )
Avatar billede guzzie Nybegynder
27. februar 2001 - 09:43 #2
hey there eagle
I got this error now
Microsoft OLE DB Provider for ODBC Drivers error \'80040e07\'

[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

/mediascope/admin/add_new_news.asp, line 20
my line 20 is the following
Con.Execute Sql
Guzzie :)
Good Morning BTW :)
Avatar billede eagleeye Praktikant
27. februar 2001 - 09:46 #3
What is the value of publish ? True / False or 1/0?

As i remenber it should be True/False.
Avatar billede eagleeye Praktikant
27. februar 2001 - 09:52 #4
Is dato a text fielt or Date field. In the insert into you have \'Date()\' indication the field is a text field. If its a Date field remove the \'\' or use # insted of \'.  VALUES(#\"&Date()&\"#,
Avatar billede dudal Nybegynder
27. februar 2001 - 10:28 #5
Remember that if a checkbox is not checket, it will not return any value.

try the following:

If Request.Form(\"publish\") <> \"\" Then
intPublished = 1
Else
intPublished = 0
End If

Then insert intPublished into the db.

Cheers
Jesper
Avatar billede guzzie Nybegynder
27. februar 2001 - 10:33 #6
Hey There
publish is a True/Flase
and dato is a date field its always worked fine
the script has only started retuning errors since I inserted publish ;(
Guzzie
Avatar billede dudal Nybegynder
27. februar 2001 - 10:36 #7
Then try using this:

If Request.Form(\"publish\") <> \"\" Then
bolPublished = TRUE
Else
bolPublished = FALSE
End If

/Jesper
Avatar billede guzzie Nybegynder
27. februar 2001 - 11:42 #8
/dudal

hey there
heres my connection
<%
Response.Buffer = True
FUNCTION fixQuotes( theString )
    fixQuotes = Replace( theString, \"\'\", \"\'\'\" )
END FUNCTION
    news_name = Request( \"news_name\" )
    news = Request( \"news\" )
    authour = Request( \"authour\" )
    email = Request( \"email\" )
    publish = Request( \"publish\" )
Set Con = Server.CreateObject( \"ADODB.Connection\" )
    DBPath = \"DBQ=\" & server.mappath(\"../media.mdb\")
    Con.Open \"DRIVER={Microsoft Access Driver (*.mdb)}; \" & DBPath
IF Request.Servervariables(\"Content_Length\") > 0 THEN
    Sql = \"INSERT INTO news (dato, news_name, news, authour, email, publish) VALUES(\'\" & Date() & \"\',\'\" & fixQuotes( news_name ) & \"\',\'\" & fixQuotes( news ) & \"\',\'\" & fixQuotes( authour ) & \"\',\'\" & fixQuotes( email ) & \"\',\' & ( publish ) & \')\"
    Con.Execute Sql
    Response.Write \"<table valign=top align=center width=750 cellpadding=5 cellspacing=0><tr><td align=center id=td_noborder_color><b><font size=3 color=red>Nyheden er nu tilføjt til databasen</font></b></td></tr></table>\"

END IF

%>
But where do I insert the script you mentioned before ?
at the start or end
Guzzie
Avatar billede tpiil Nybegynder
27. februar 2001 - 11:46 #9
det hedder On/Off i databasen...
Avatar billede guzzie Nybegynder
27. februar 2001 - 11:49 #10
Ok I try again this is my new connection
<%
Response.Buffer = True
FUNCTION fixQuotes( theString )
    fixQuotes = Replace( theString, \"\'\", \"\'\'\" )
END FUNCTION
    news_name = Request( \"news_name\" )
    news = Request( \"news\" )
    authour = Request( \"authour\" )
    email = Request( \"email\" )
    publish = Request( \"publish\" )
    if publish = \"True\" then
        publish = True
    else
        publish = False
    end if
Set Con = Server.CreateObject( \"ADODB.Connection\" )
    DBPath = \"DBQ=\" & server.mappath(\"../media.mdb\")
    Con.Open \"DRIVER={Microsoft Access Driver (*.mdb)}; \" & DBPath
IF Request.Servervariables(\"Content_Length\") > 0 THEN
    Sql = \"INSERT INTO news (dato, news_name, news, authour, email, publish) VALUES(\'\" & Date() & \"\',\'\" & fixQuotes( news_name ) & \"\',\'\" & fixQuotes( news ) & \"\',\'\" & fixQuotes( authour ) & \"\',\'\" & fixQuotes( email ) & \"\',\' & ( publish ) & \')\"
    Con.Execute Sql
    Response.Write \"<table valign=top align=center width=750 cellpadding=5 cellspacing=0><tr><td align=center id=td_noborder_color><b><font size=3 color=red>Nyheden er nu tilføjt til databasen</font></b></td></tr></table>\"

END IF

%>

I now get this error
Microsoft OLE DB Provider for ODBC Drivers error \'80040e07\'

[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

/mediascope/admin/add_new_news.asp, line 25

Line 25 is this
    Con.Execute Sql
Guzzie
Avatar billede guzzie Nybegynder
27. februar 2001 - 11:51 #11
/tpiil It kan be on/off  or True/Flase
I use this
SQLstmp = \"SELECT * FROM news where publish = True ORDER BY dato ;\"
on another asp page and it works fine
Guzzie
Avatar billede dudal Nybegynder
27. februar 2001 - 12:20 #12
Try this then :-)

I removed the \' around publish.

Sql = \"INSERT INTO news (dato, news_name, news, authour, email, publish) VALUES(\'\" & Date() & \"\',\'\" & fixQuotes( news_name ) & \"\',\'\" & fixQuotes( news ) & \"\',\'\" & fixQuotes( authour ) & \"\',\'\" & fixQuotes( email ) & \"\',\" & ( publish ) & \")\"

/Jesper
Avatar billede guzzie Nybegynder
27. februar 2001 - 12:36 #13
kewl that works nicley thx :)

Guzzie
Avatar billede guzzie Nybegynder
27. februar 2001 - 12:48 #14
btw dudal
I was thinking that If I have an asp page that takes the contents of the database and puts them in a form then the normal
value=\"<%=rs(\"publish\")%>\"
does not work hmmm
if you can help I would appreciate it
I can start a new question if need be :(
sorry about all the bother but I just have not worked with check boxes before
Guzzie
Avatar billede dudal Nybegynder
27. februar 2001 - 12:52 #15
<input type=\"checkbox\" name=\"publish\" value=\"true\"<%= If Rs(\"Publish\") = TRUE THEN Response.Write \" checked\" %>>

:-) Jesper
Avatar billede guzzie Nybegynder
27. februar 2001 - 13:10 #16
:) me try that
I was thinking like this hihi
<INPUT TYPE=\"checkbox\" VALUE=\"<% if publish = True Then publish = True else publish = False End If %>\" NAME=\"publish\">
Avatar billede guzzie Nybegynder
27. februar 2001 - 13:12 #17
ok I got this error
Microsoft VBScript compilation error \'800a03ea\'

Syntax error

/mediascope/admin/edit_news.asp, line 60

Response.Write(If Rs(\"publish\") = TRUE THEN Response.Write \" checked\")
---------------^

but cant quite seem to see where syntax is wrong
Avatar billede guzzie Nybegynder
27. februar 2001 - 13:30 #18
Oops :)
I worked it out
this works fine

<INPUT TYPE=\"checkbox\" VALUE=\"True\" NAME=\"publish\" <% if rs(\"Publish\") = \"True\" Then %>CHECKED<% end if %>>

thanks again dudal

Guzzie
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester