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?
Compare bible texts (and other tools): TheWheelofGod
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
%>
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 ..
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.
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"
%>
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
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?
Compare bible texts (and other tools): TheWheelofGod
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.
Last edited by gilgalbiblewhee; Jun 16th, 2006 at 05:10 PM.
Compare bible texts (and other tools): TheWheelofGod
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 ..
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 ..??
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();">