| |
arvinbocs
Posts: 1
Score: 0
Joined: 9/23/2008
Status: offline
|
I am working on a form that needs to be able to add record in the database and upload file at the same time. Is there a way of doing this? I was able to do a form that uploads files and updated records on a database but not together or as one. When I combine the two, it always fails. Please help. Here's my code: UPDATERECORD.ASP <html> <head> <title> Adding to database example </title> <script type="text/javascript"> <!-- function validate() { if(document.form.title.value=="") { alert("Title is missing"); return false; } } //--> </script> </head> <body> <form name="form" method="post" action="save.asp"> <p align="center"><b>Add Project Type:</b></p> <table align="center" border=0 cellpadding=3 cellspacing=3 cols=2 width=400> <tr> <td align="right" height=10 valign="top">Num :</td> <td align="left" height=10 valign="top" width=250><input type="text" name="num"/></td> </tr> <tr> <td align="right" height=10 valign="top">Category :</td> <td align="left" height=10 valign="top" width=250> <select name="category" size="1"> <option value="Residential">Residential</option> <option value="Commercial/Industrial">Commercial/Industrial</option> <option value="Landfill/Overburden">Landfill/Overburden</option> <option value="Roadwork">Roadwork</option> <option value="Demolition">Demolition</option> <option value="Wetlands">Wetlands</option> <option value="Underground">Underground</option> <option value="Other">Other</option> </select> </td> </tr> <tr> <td align="right" height=10 valign="top">Title :</td> <td align="left" height=10 valign="top" width=250><input type="text" name="title"/></td> </tr> <tr> <td align="right" height=10 valign="top">File :</td> <td align="left" height=10 valign="top" width=250><input type="file" name="elementName"/></td> </tr> <tr> <td align="right" height=10 valign="top"></td> <td align="left" height=10 valign="top" width=200><input type="submit" name="Save" value="Submit" onclick="return validate();"/></td> </tr> </table> </form> </body> </html> SAVE.ASP <% Dim Conn Dim Rs Dim sql 'Create an ADO connection and recordset object Set Conn = Server.CreateObject("ADODB.Connection") Set Rs = Server.CreateObject("ADODB.Recordset") 'Set an active connection and select fields from the database Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("category.mdb") sql= "SELECT * FROM projtype;" 'Set the lock and cursor type Rs.CursorType = 2 Rs.LockType = 3 'Open the recordset with sql query Rs.Open sql, Conn 'Prepare the database to add a new record and add Rs.AddNew Rs.Fields("num") = Request.Form("num") Rs.Fields("category") = Request.Form("category") Rs.Fields("title") = Request.Form("title") 'Save the update Rs.Update Rs.Close Set Rs = Nothing Set Conn = Nothing Response.Redirect "cmsprojectshowall.asp" %>
|
|