Putting data into Database.
Wanted to ad data into a database via vbscript, and I have worked it out now. Thank you very much. :)
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
anonymous_9363
13 years ago
Posted by:
JohnCena83
13 years ago
<%
[/align]if request.form("submit") <>"" then
[/align] set conn=Server.CreateObject("ADODB.Connection")
[/align] conn.Provider="Microsoft.Jet.OLEDB.4.0"
[/align] conn.Open server.mapPath("northwind.mdb")
[/align]
[/align] sql="INSERT INTO customers (customerID,companyname,"
[/align] sql=sql & "contactname,address,city,postalcode,country)"
[/align] sql=sql & " VALUES "
[/align] sql=sql & "('" & Request.Form("custid") & "',"
[/align] sql=sql & "'" & Request.Form("compname") & "',"
[/align] sql=sql & "'" & Request.Form("contname") & "',"
[/align] sql=sql & "'" & Request.Form("address") & "',"
[/align] sql=sql & "'" & Request.Form("city") & "',"
[/align] sql=sql & "'" & Request.Form("postcode") & "',"
[/align] sql=sql & "'" & Request.Form("country") & "')"
[/align]
[/align] response.write "sql = " & sql
[/align]
[/align] on error resume next
[/align] conn.Execute sql,recaffected
[/align] if err<>0 then
[/align] Response.Write(err.description)
[/align] else
[/align] Response.Write("<h3>" & recaffected & " record added</h3>")
[/align] end if
[/align] conn.close
[/align]
[/align]else
[/align] response.write "no record added"
[/align]end if
[/align]%>
[/align]
[/align]
[/align]<html>
[/align]<body>
[/align]
[/align]<form method="post" action="">
[/align]<table>
[/align]<tr>
[/align]<td>CustomerID:</td>
[/align]<td><input name="custid" value="1111"></td>
[/align]</tr><tr>
[/align]<td>Company Name:</td>
[/align]<td><input name="compname" value="myName"></td>
[/align]</tr><tr>
[/align]<td>Contact Name:</td>
[/align]<td><input name="contname" value="myContactName"></td>
[/align]</tr><tr>
[/align]<td>Address:</td>
[/align]<td><input name="address" value="myAddress"></td>
[/align]</tr><tr>
[/align]<td>City:</td>
[/align]<td><input name="city" value="myCity"></td>
[/align]</tr><tr>
[/align]<td>Postal Code:</td>
[/align]<td><input name="postcode" value="12345"></td>
[/align]</tr><tr>
[/align]<td>Country:</td>
[/align]<td><input name="country" value="myCountry"></td>
[/align]</tr>
[/align]</table>
[/align]<br /><br />
[/align]<input name ="submit" type="submit" value="Add New">
[/align]<input type="reset" value="Cancel">
[/align]</form>
[/align]
[/align]</body>
[/align]</html>[/align][/align]
[/align]if request.form("submit") <>"" then
[/align] set conn=Server.CreateObject("ADODB.Connection")
[/align] conn.Provider="Microsoft.Jet.OLEDB.4.0"
[/align] conn.Open server.mapPath("northwind.mdb")
[/align]
[/align] sql="INSERT INTO customers (customerID,companyname,"
[/align] sql=sql & "contactname,address,city,postalcode,country)"
[/align] sql=sql & " VALUES "
[/align] sql=sql & "('" & Request.Form("custid") & "',"
[/align] sql=sql & "'" & Request.Form("compname") & "',"
[/align] sql=sql & "'" & Request.Form("contname") & "',"
[/align] sql=sql & "'" & Request.Form("address") & "',"
[/align] sql=sql & "'" & Request.Form("city") & "',"
[/align] sql=sql & "'" & Request.Form("postcode") & "',"
[/align] sql=sql & "'" & Request.Form("country") & "')"
[/align]
[/align] response.write "sql = " & sql
[/align]
[/align] on error resume next
[/align] conn.Execute sql,recaffected
[/align] if err<>0 then
[/align] Response.Write(err.description)
[/align] else
[/align] Response.Write("<h3>" & recaffected & " record added</h3>")
[/align] end if
[/align] conn.close
[/align]
[/align]else
[/align] response.write "no record added"
[/align]end if
[/align]%>
[/align]
[/align]
[/align]<html>
[/align]<body>
[/align]
[/align]<form method="post" action="">
[/align]<table>
[/align]<tr>
[/align]<td>CustomerID:</td>
[/align]<td><input name="custid" value="1111"></td>
[/align]</tr><tr>
[/align]<td>Company Name:</td>
[/align]<td><input name="compname" value="myName"></td>
[/align]</tr><tr>
[/align]<td>Contact Name:</td>
[/align]<td><input name="contname" value="myContactName"></td>
[/align]</tr><tr>
[/align]<td>Address:</td>
[/align]<td><input name="address" value="myAddress"></td>
[/align]</tr><tr>
[/align]<td>City:</td>
[/align]<td><input name="city" value="myCity"></td>
[/align]</tr><tr>
[/align]<td>Postal Code:</td>
[/align]<td><input name="postcode" value="12345"></td>
[/align]</tr><tr>
[/align]<td>Country:</td>
[/align]<td><input name="country" value="myCountry"></td>
[/align]</tr>
[/align]</table>
[/align]<br /><br />
[/align]<input name ="submit" type="submit" value="Add New">
[/align]<input type="reset" value="Cancel">
[/align]</form>
[/align]
[/align]</body>
[/align]</html>[/align][/align]
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.