| |

VerySource

 Forgot password?
 Register
Search
View: 906|Reply: 7

Guestbook question

[Copy link]

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Russia

Post time: 2020-3-14 16:30:01
| Show all posts |Read mode
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "Content-Type" content = "text / html; charset = gb2312" />
<title> Guestbook </ title>
<style type = "text / css">
<!-
.style1 {font-size: 12px}
.style2 {font-size: 12px; font-weight: bold;}
->
</ style>
</ head>

<body>
<%
set conn = server.createobject ("adodb.connection")
conn.connectionstring = "driver = {sql server}; server = .; database = lyb.mdb; uid = sa; pwd = 12345;"
%>
<%
title = request.form ("title")
if title <> "" then
set rs = server.createobject ("adodb.recordset")
rs.open "lyb", conn, 3,3
rs.addnew
rs ("title") = title
rs ("content") = request.form ("content")
rs ("datetime") = now ()
rs.update
end if
%>
<form name = "form1" method = "post" action = "">
<p align = "center" class = "style2"> Guestbook-Add message content </ p>
<table width = "479" border = "0" align = "center" cellpadding = "5" cellspacing = "1" bgcolor = "# cccccc">
<tr bgcolor = "# ffffff">
<td width = "86"> <div align = "center"> <span class = "sytle1"> Title: </ span> </ div> </ td>
<td width = "304" height = "30"> <input name = "title" type = "text" id = "title"> </ td>
</ tr>
<tr bgcolor = "# ffffff">
<td> <div align = "center"> <span class = "sytle1"> Content: </ span> </ div> </ td>
<td> <textarea name = "content" cols = "50" rows = "20" id = "content"> </ textarea> </ td>
</ tr>
<tr bgcolor = "# ffffff">
<td colspan = "2"> <div align = "center">
<input type = "submit" name = "submit" value = "submit">
<input type = "button" name = "submit" value = "view message" onclick = "location" href = 'showcontent.asp'>
<input type = "reset" name = "submit" value = "Reset">
</ div>
</ td>
</ tr>
</ table>
</ form>
</ body>
</ html>
After this code was executed, a form came out, but this problem occurred when I submitted the data to the data.
Error type:
ADODB.Recordset (0x800A0E7D)
Connection cannot be used to perform this operation. It may be closed or invalid in this context.
/TEST/addcontent.asp, line 24
Please help to see, it's been an afternoon, it's really anxious.
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-6-12 02:15:01
| Show all posts
rs.open "lyb",conn,3,3 ---- This place is even more wrong! Should write sentences!
rs.open "select * from tablename", conn,3,3 --- replace the tablename in this place with the name of the table you want to insert
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-6-12 12:45:01
| Show all posts
<%
set conn=server.createobject("adodb.connection")
conn.connectionstring="driver={sql server};server=.;database=lyb.mdb;uid=sa;pwd=12345;"
%>
<%
title=request.form("title")
if title<>"" then
set rs=server.createobject("adodb.recordset")
rs.open "lyb",conn,3,3
rs.addnew
rs("title")=title
rs("content")=request.form("content")
rs("datetime")=now()
rs.update
end if
%>

Replace this place with the following statement

<%
set conn=server.createobject("adodb.connection")
conn.connectionstring="driver={sql server};server=.;database=lyb.mdb;uid=sa;pwd=12345;"

title = request.form("title")
content = request.form("content")
if title<>"" then
sql = "insert into tablename(title,content,datetime) values('"&title&"','"&content&"',getdate())"
conn.execute sql
end if
%>
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-6-20 10:00:02
| Show all posts
Thank you for your answer. But still not.
   I'm a novice, please don't joke when you ask a question. ('"&title&"','"&content&"',getdate()) I don't quite understand the format of&title&in this sentence, can you explain it in detail. Thank you very much!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-24 19:00:02
| Show all posts
Thank you for your answer. But still not.
   I'm a novice, please don't joke when you ask a question. ('"&title&"','"&content&"',getdate()) I don't quite understand the format of&title&in this sentence, can you explain it in detail. Thank you very much!

Here "&title&"','"&content&"' parameters, this way is a parameterized query!
Reply

Use magic Report

0

Threads

10

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-7-11 18:00:02
| Show all posts
'"&title&"','"&content&"',getdate())
I don’t understand the format of&title&in this sentence, can I explain it in detail?

You wrote earlier
title=request.form("title")
That is, title as a variable, accepted the value passed from the previous page (content is the same)
getdate (take the current time in SQL SERVER)
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 Unknown

Post time: 2020-7-13 03:15:01
| Show all posts
Is it an error, or there is no result~~
You print the sql statement first    response.write sql
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-18 23:15:02
| Show all posts
The good-hearted person upstairs, after changing according to your method, can't submit the interface data to the database. After submitting it, this will be displayed. Could you please help to see what is going on.
Error type:
ADODB.Connection (0x800A0E78)
No operation is allowed when the object is closed.
/TEST/addcontent.asp, line 24
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list