-
why doesn't it insert in database?
Code:
<html>
<body>
<form action="feedbacksent.asp" method="get" enctype="text/plain">
<h3>Your feedback is important.</h3>
<h5>To send your comments put your:</h5><br>
Name:<br>
<input type="text" name="name" size="18" value="Put your name" class="form-input" onBlur="if(this.value==''){this.value='Put your name';}" onFocus="if(this.value=='Put your name'){this.value='';}">
<br>
Email:<br>
<input type="text" name="email" size="22" value="Put your email address" class="form-input" onBlur="if(this.value==''){this.value='Put your email address';}" onFocus="if(this.value=='Put your email address'){this.value='';}">
<br>
Subject:<br>
<input type="text" name="subject" size="40" value="Put your subject" class="form-input" onBlur="if(this.value==''){this.value='Put your subject';}" onFocus="if(this.value=='Put your subject'){this.value='';}">
<br>
<textarea rows="10" name="comment" cols="60" value="Put your comments" class="form-input" onBlur="if(this.value==''){this.value='Put your comments';}" onFocus="if(this.value=='Put your comments'){this.value='';}"></textarea>
<br><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
</body>
</html>
Code:
<html>
<body>
<%
'Dim connStr
'connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("Kjv.mdb")
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "kjv.mdb"
sql="INSERT INTO feedback (ID,name,"
sql=sql & "subject,email,comment)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("ID") & "',"
sql=sql & "'" & Request.Form("name") & "',"
sql=sql & "'" & Request.Form("email") & "',"
sql=sql & "'" & Request.Form("subject") & "',"
sql=sql & "'" & Request.Form("comment") & "')"
on error resume next
conn.Execute sql,recaffected
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
%>
</body>
</html>
-
Re: why doesn't it insert in database?
Whats the error message ..?
Is ID a number or text field, you are using it as a text field there. .
Also, I would put them all into variables first.
Rory
-
Re: why doesn't it insert in database?
I didn't see any errors. But I'm thinking that I need a hidden type and call it name=ID. But how am I going to make sure that it inserts and not update in the database?
-
Re: why doesn't it insert in database?
Just off the top of my head .. try this ..
ID would normally be an auto number and not needed to insert into but that depends how you create the database ..
Here is how it should look a little more like .. (Request.Form if it is a form)
I dont know where you are getting ID and recaffected from though ?
I left the ID out ..
Code:
<%
Option Explicit
Dim objConn
Dim sql
Dim rsID
Dim rsName
Dim rsEmail
Dim rsSubject
Dim rsComment
On Error Resume Next
rsName = Request("name")
rsEmail = Request("email")
rsSubject = Request("subject")
rsComment = Request("comment")
Set objConn = SERVER.CREATEOBJECT("ADODB.Connection")
objConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & _
"DBQ=" & Server.Mappath("./Kjv.mdb")
sql="INSERT INTO feedback (name,"
sql=sql & "subject,email,comment)"
sql=sql & " VALUES "
sql=sql & "('" & rsName & "',"
sql=sql & "'" & rsEmail & "',"
sql=sql & "'" & rsSubject & "',"
sql=sql & "'" & rsComment & "')"
objConn.Execute sql
objConn.Close
Set objConn = Nothing
If Err <> 0 Then
Response.Write "Database Error!<br>"
Response.Write Err.Description
Else
Response.Write "<h3>New Record Added</h3>"
End If
%>
-
Re: why doesn't it insert in database?
no it didn't work. ALthough there are no errors, it says "No update permissions!" meaning:
err<>0
Isn't it because of the ID not found in the first page (in a hidden object)?
-
Re: why doesn't it insert in database?
Try it again .. i just edited it to leave out the ID and rec affected vars, and also added in the error description .. let me know what it sais now after you use this code ..
Also, is your database located in the path you are running this page ..? Or elsewhere ..? And are those fields in the database and are they all text fields ..?
Post your database file or PM me if it if you like ..
Rory
-
1 Attachment(s)
Re: why doesn't it insert in database?
I don't know.I tried it. Here...
-
Re: why doesn't it insert in database?
Ok, problem was the Form .. this is all you need .. you could name it too if you wanted .. but not needed.
<form action="feedbacksent.asp" method="post">
updated and added attachment ..
Rory
-
Re: why doesn't it insert in database?
Thanks. How does the ID number? because the number is at 22. Also how to redirect to mailto.asp?
-
Re: why doesn't it insert in database?
The ID is auto number .. never have to touch that ..
If you delete a record the next insert will still continue on + 1
Redirect ..? You mean back to the Form page?
Response.Redirect "mailto.asp"
if you need a more custom ID I would add that field seperately .. maybe by date/time and create it as an Integer (number). I use reference or Sku Numbers in my databases but thats a little different.
-
Re: why doesn't it insert in database?
what if I want to redirect in 3 seconds?
-
Re: why doesn't it insert in database?
Best to redirect to another page and use the Meta Refresh tag in that page ..
Otherwise here is a VBscript timer example ..
This may cause issues on the server though(?) if used incorrectly or for long periods ..
Stop and Start Watch are just there as a chrono ..
Code:
<%@ Language="VBScript" %>
<%
Option Explicit
Response.Buffer = True
Dim StopWatch(19)
Dim x
Sub StartTimer( byRef x )
StopWatch(x) = timer
End Sub
Function StopTimer( byRef x )
DIM EndTime
EndTime = Timer
IF EndTime < StopWatch(x) THEN
EndTime = EndTime + (86400)
END IF
StopTimer = EndTime - StopWatch(x)
End Function
Function usrDelay(nSeconds)
Dim nStoptime
nStoptime = Timer + nSeconds
Do While Timer <= nStoptime
Loop
End Function
StartTimer x
Response.Write "Timer Started"
Response.Flush
usrDelay 3
Response.Write "<br>Elapsed Time: "
Response.Write FormatNumber(StopTimer(x),1) & "sec"
%>
-
Re: why doesn't it insert in database?
This is how you would use it in your script ..
Code:
Function usrDelay(nSeconds)
Dim nStoptime
nStoptime = Timer + nSeconds
Do While Timer <= nStoptime
Loop
End Function
If Err <> 0 Then
Response.Write "Database Error!<br>"
Response.Write Err.Description
Response.End
Else
usrDelay 3
Response.Redirect "mailto.asp"
End If
-
Re: why doesn't it insert in database?
The last one didn't work:
Code:
Function usrDelay(nSeconds)
Dim nStoptime
nStoptime = Timer + nSeconds
Do While Timer <= nStoptime
Loop
End Function
If Err <> 0 Then
Response.Write "Database Error!<br>"
Response.Write Err.Description
Response.End
Else
Response.Write "<center><h3>Thank You For your Feedback!</h3></center>"
usrDelay 3
Response.Redirect "mailto.asp"
End If
By the way I meant to ask the punctuation marks don't allow the script to work properly. If I type don't or a question or anything else it blocks the script. Is there a way around that?
-
Re: why doesn't it insert in database?
It didnt redirect or didnt delay?
use this to correct your text before entering into a database ..
Like this ..
rsComment = Correct_String(Request("comment"))
Code:
'// CLEAN ' FROM DATABASE STRING
Function Correct_String(ByVal rStr)
Correct_String = Replace(rStr, "'", "''")
End Function
-
Re: why doesn't it insert in database?
http://d.1asphost.com/infowars/scarl...ast/mailto.asp
Check it out.
What does the code do:
Quote:
Originally Posted by rory
Code:
'// CLEAN ' FROM DATABASE STRING
Function Correct_String(ByVal rStr)
Correct_String = Replace(rStr, "'", "''")
End Function
-
Re: why doesn't it insert in database?
Replaces the single colon with 2 colons for entry into the database ...
-
Re: why doesn't it insert in database?
Hmmm, with the redirect .. okay then use a redir page instead .. less stress on the server anyway ..
In your code ..
Code:
If Err <> 0 Then
Response.Write "Database Error!<br>"
Response.Write Err.Description
Response.End
Else
Response.Redirect "redir.asp"
End If
Then the Redir.asp (or .htm doesnt matter) page
Code:
<html>
<head>
<meta http-equiv="refresh" content="3;url=mailto.asp">
<title>Thank you</title>
</head>
<body>
<center><h3>Thank You For your Feedback!</h3></center>
</body>
</html>
-
Re: why doesn't it insert in database?
Quote:
Originally Posted by rory
Replaces the single colon with 2 colons for entry into the database ...
I'm not sure I understand. Will it pass all these into the database:
And anything else used in Scripting?
If there is a solution it would be nice. I have a similar problem where I use a database of Hebrew. Some of the Hebrew letters are actually punctuation marks. So when I type to search a particular word it would show error.
-
Re: why doesn't it insert in database?
single colon is the only thing to check for ..
When you enter '' into the database through code, the database sees it as a single colon .. if you just enter ' into the database in the query you will get an error ..
-
Re: why doesn't it insert in database?
Ok so what about ? ! and others?
-
Re: why doesn't it insert in database?
they're fine .. see ' is used in the query for text so it will cause an error if not converted to ''
Example Error ..
Select * From table where field like 'don't' ...
-
Re: why doesn't it insert in database?
ok I see what you mean. I put:
Code:
sql="INSERT INTO feedback (name,"
sql=sql & "subject,email,comment)"
sql=sql & " VALUES "
sql=sql & "('" & rsName & "',"
sql=sql & "'" & rsEmail & "',"
sql=sql & "'" & rsSubject & "',"
sql=sql & "'" & rsComment & "')"
'// CLEAN ' FROM DATABASE STRING
Function Correct_String(ByVal rStr)
Correct_String = Replace(rStr, "'", "''")
End Function
objConn.Execute sql
objConn.Close
Set objConn = Nothing
But it said:
Quote:
Database Error!
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression ''don't','do')'.
-
Re: why doesn't it insert in database?
right, so since any of these fields can ultimately contain the single colon as the user is entering them manually ..
Do this ..
rsName = Correct_String(Request("name"))
rsEmail = Correct_String(Request("email"))
rsSubject = Correct_String(Request("subject"))
rsComment = Correct_String(Request("comment"))
There is other error checking you could do ... such as check for valid email, make sure the Name is a string, make sure they enter something in each field, .. but this should cover it in this case ..
You can, instead of using the Function, just do something like this also ..
rsName = Replace(Request("name"),"'","''")
Another thing though .. you may want to add some validation if they dont enter their name or other field, the "Put your ... " gets entered into the database ..??
-
Re: why doesn't it insert in database?
Now it says:
Quote:
Database Error!
Operation is not allowed when the object is closed.
...
Oh I see the db is renamed that's why.
-
Re: why doesn't it insert in database?
Hmmm, anyway, some basic javascript validation on each field, means they must enter a field, as in the database you have it set up as to not allow blank fields .. then you must validate it somehow ... i normally do it in ASP and send them back with the fields missing in red text .. but here is the javascript way .. this replaces the top of the mailto page .. starting at the very top and ending with the Form tag.
Code:
<html>
<head>
<Script Language="JavaScript">
function Form_Submit() {
if ((feedback.name.value=='Put your name') ||
(feedback.name.value==''))
{
alert("Please Enter Your Name");
return false;
}
else if ((feedback.email.value=='Put your email address') ||
(feedback.email.value==''))
{
alert("Please Enter Your Email Address");
return false;
}
else if ((feedback.subject.value=='Put your subject') ||
(feedback.subject.value==''))
{
alert("Please Enter Your Subject");
return false;
}
else if ((feedback.comment.value=='Put your comments') ||
(feedback.comment.value==''))
{
alert("Please Enter Your Comments");
return false;
}
else { return true; }
}
</script>
</head>
<body>
<form action="feedbacksent.asp" method="post" name="feedback" onSubmit="return Form_Submit();">
-
Re: why doesn't it insert in database?
I haven't gone that far because I haven't received plenty of trafik. Since it's freewebhosting often the file manager doesn't even function properly.