|
The following code runs but does not insert any data! PLS Help!!
<html>
<head>
<title></title>
</head>
<form method="post" >
<table width="997" height="233">
<tr> <td width="417" height="35">
<b><font size="2">Your Name</font></b>
<td width="822" height="229" rowspan="11" valign="top">
<p class="MsoNormal"><span style="mso-tab-count:2"><font size="1">
</tr>
<tr> <td width="417" height="1" valign="top">
<INPUT type="text" NAME="yourname" ><br>
</tr>
<tr> <td width="417" height="22">
<B> <font size="2"> E-mail</font></B>
</tr>
<tr> <td width="417" height="32" valign="top">
<INPUT TYPE="TEXT" NAME="email" >
</tr>
<tr> <td width="417" height="22">
<B><font size="2">Street Address</font>
</B>
</tr>
<tr>
<td width="417" height="32" valign="top">
<INPUT TYPE="TEXT" NAME="add" >
</tr>
<tr> <td width="417" height="27">
<B><font size="2">City </font> <font size="2">State
Zip</font></b> </td> </tr>
<tr> <td width="417" height="32" valign="top">
<INPUT TYPE="TEXT" NAME="city" size="18" > <input type="text" name="state" size="12">
<input type="text" name="zip" size="12">
</td>
<tr>
<td width="417" height="22">
<b>
<font size="2">
Comments</font></b> </td></tr>
<tr><td width="417" height="243" valign="top">
<TEXTAREA NAME="msg" ROWS=6 COLS=35></TEXTAREA>
<p>
<INPUT TYPE="SUBMIT" NAME="submit" VALUE="Submit Statement">
</tr>
<tr> <td width="417" height="1">
</tr>
</form>
<b>
<%
Dim Conn, dbPath
dbpath="d:\data\test.mdb"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath
Set rst = Server.CreateObject("ADODB.Recordset")
`sql="INSERT INTO comments (Name,Email,Address,City,State,Zip,Comments)"
`sql=sql & "VALUES "
`sql=sql & "(`" & trim(Request.Form("yourname")) &"`,"
`sql=sql & "`" & trim(Request.Form("email")) & "`,"
`sql=sql & "`" & trim(Request.Form("add")) & "`,"
`sql=sql & "`" & trim(Request.Form("city")) & "`,"
`sql=sql & "`" & trim(Request.Form("state")) & "`,"
`sql=sql & "`" & trim(Request.Form("zip")) & "`,"
`sql=sql & "`" & trim(Request.Form("msg")) & "`)"
Sub CheckValid(Str)
Str = Replace(Str, "`", "``")
If Str = "" THEN
Str= " "
End If
End Sub
dim msgname,msgemail,msgadd,msgstate,msgcity,msgm
sql1="INSERT into comments1(Name_t,Email_t,Address_t,City_t,State_t,Zip_t,Comments_t)values(`"& msgname & "`,`"& msgemail &"`,`" & msgadd &"`,` "& msgcity & "`,`"& msgstate &"`,`"& msgzip &"`,`"& msgm &"`);"
`msgname= Request.Form("yourname")
msgname = server.HTMLencode(Request.Form("yourname"))
msgemail= trim(Request.Form("email"))
msgadd= trim(Request.Form("add"))
msgcity= trim(Request.Form("city"))
msgstate= trim(Request.Form("state"))
msgzip= trim(Request.Form("zip"))
msgm= trim(Request.Form("msg"))
Call CheckValid(msgname)
Call CheckValid(msgemail)
Call CheckValid(msgadd)
Call CheckValid(msgcity)
Call CheckValid(msgstate)
Call CheckValid(msgzip)
Call CheckValid(msgm)
`sql="INSERT into comments(Name,Email,Address,City,State,Zip,Comments)values(`Request.Form("yourname")`,`&msgemail&`,` & msgadd &`,`& msgcity &`,`& msgstate &`,`& msgzip &`,`& msgm &`);"
set rst=Conn.Execute(sql1)
response.write(sql1)
`rst.Update
If rst.State = 1 Then
rst.Close
end if
Set rst = Nothing
set Conn= Nothing
%> </b>
</table>
</body>
|
|
|
Response.Write Your SQL
First,Are you sure your sql is right?
and data from form is right?
You Must Replace ` In Data from form
Replace(string,"`","``"),Otherwise the sql sentence will error
My English is poor.
|
|
|
Sunway makes a good point. Whenever I have a problem with a SQL statement, I response.write the statement, then copy and paste that either into Query Analyzer for SQL Server or into a Query window in Access. These tools will help you fix the query with syntax highlighting and detailed error messages.
|
|
|
|
|
Thank you for responding Data is inserted as I can see an autonumber(date value which is set to date() in access) holds a value but the rest of the fields are all empty
My Data looks like this..
Name email date_entered
8/11/03
8/11/03
8/11/03
1 of 3 records (in the status bar)
Pls respond..
Thank you,
lets.
|
|
|
Is the code you posted your actual code?
Normally, you`d have your page set to either write out the form or process the form and write out a thank you page (or redirect to a thank you page). This page will always write out a form AND run your code to process the form. So the first time this page loads, you write out a form to the browser and insert an empty record.
Your code: Your first build a sql statement into the variable "sql", but you never do anything with this query! Then you build a sql statement into a variable "sql1", but you build it with variables that you have not populated yet! Then you build a sql statement into the "sql" variable again, but never do anything with this query (again)! Lastly, you Execute "sql1" which is a bunch of empty values.
So there are multiple problems with this code. From what I see, it looks like the first time you build "sql", it should work fine, just Execute that. But you need to add code to not insert a record unless a form was submitted. Right now, it will insert a record everytime the page is run.
|
|
|
|
|
|
|
|
|
// |