User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP section within the Web Development category of DaniWeb, a massive community of 455,964 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,609 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP advertiser: Lunarpages ASP Web Hosting
Views: 931 | Replies: 3
Reply
Join Date: Sep 2007
Posts: 9
Reputation: Varelei is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Varelei Varelei is offline Offline
Newbie Poster

Help Add Products to Products Table

  #1  
Nov 19th, 2007
The problem is that I cannot get my Add Products to work. Below is the source coding for both the entry form and the .asp processing. Can anyone tell me what is wrong with this code? Help is greatly appreciated, and so is a final solution! I'll add reputation to whoever can get this working for me. Oh, and it uses the Northwind.mdb sample that came with Access 2003.

(ENTRY FORM) - FILENAME: myindex.html
<html>
<body>

<form method="post" action="product_append.asp">
<table>
<tr>
<td>Product ID:</td>
<td><input name="prodid"></td>
</tr><tr>
<td>Company Name:</td>
<td><input name="prodname"></td>
</tr><tr>
<td>Supplier ID:</td>
<td><input name="suppid"></td>
</tr><tr>
<td>Category ID:</td>
<td><input name="catid"></td>
</tr><tr>
<td>Quantity of Stock:</td>
<td><input name="quantity"></td>
</tr><tr>
<td>Unit Price:</td>
<td><input name="unitprice"></td>
</tr><tr>
<td>Unit Stock:</td>
<td><input name="unitstock"></td>
</tr><tr>
<td>Units On Order:</td>
<td><input name="unitorder"></td>
</tr><tr>
<td>Reorder Level:</td>
<td><input name="reorderlevel"></td>
</tr>
</table>
<br /><br />
<input type="submit" value="Add New"> 
<input type="reset" value="Cancel">
</form>

</body>
</html>

(ASP PROCESSING) - FILENAME: product_append.asp
<html>
<body>

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/Inetpub/wwwroot/northwind.mdb"

sql="INSERT INTO Products (Product_ID,Product_Name,"
sql=sql & "Supplier_ID,Category_ID,Quantity_Per_Unit,Unit_Price,Units_In_Stock,Units_On_Order,Reorder_Level)"
sql=sql & " VALUES "
sql=sql & "'" & Request.Form("prodid") & "',"
sql=sql & "'" & Request.Form("prodname") & "',"
sql=sql & "" & Request.Form("suppid") & ","
sql=sql & "" & Request.Form("catid") & ","
sql=sql & "'" & Request.Form("quantity") & "',"
sql=sql & "'" & Request.Form("unitprice") & "',"
sql=sql & "" & Request.Form("unitstock") & ","
sql=sql & "" & Request.Form("unitorder") & ","
sql=sql & "" & Request.Form("reorderlevel") & ")"

'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>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2007
Posts: 48
Reputation: CertGuard is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 3
CertGuard's Avatar
CertGuard CertGuard is offline Offline
Light Poster

Re: Add Products to Products Table

  #2  
Nov 26th, 2007
The only issue that I see is that your Form is on a different page, so Request.Form won't work in your case. Try replacing Request.Form with Request.Querystring.

When the submit button on myindex.html is clicked, it should send all of your name="value" pairs to product_append.asp through querystrings.

IOW, With no values in any of the textboxes, you should see something like this in your address bar after you've clicked the Add New button:

/product_append.asp?prodid=&prodname=&suppid=&catid=&quantity=&unitprice=&unitstock=&unitorder=&reorderlevel&Submit=Add+New

The only problem with using this method is that you're limited to the MAXLENGTH of the characters allowed in the addressbar.

Good Luck!
--
Robert Williams
CEO, Founder
CertGuard
Reply With Quote  
Join Date: Sep 2007
Posts: 9
Reputation: Varelei is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Varelei Varelei is offline Offline
Newbie Poster

Re: Add Products to Products Table

  #3  
Nov 27th, 2007
Thanks, I'll give it a shot.
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Add Products to Products Table

  #4  
Nov 28th, 2007
Actually, the request.form will work perfectly fine as your form is set to the action of your processing page. The problem you are incurring is dealt by the limited information on your form page. Your input fields should be a minimum of this:
<input type="text" name="name">

Should be this:
<input type="text" name="name" id="name">

Since your input fields are not set to a type, it doesn't know exactly what to request.

Also you shouldn't add your form elements directly into the query. Declare your variables first then add the variables in. I have redone your information so please plug-in-play.
Entry page:

<html>
<body>

<form method="post" action="product_append.asp">
<table>
<tr>
<td>Product ID:</td>
<td><input type="text" id="prodid" name="prodid"></td>
</tr><tr>
<td>Company Name:</td>
<td><input type="text" id="prodname" name="prodname"></td>
</tr><tr>
<td>Supplier ID:</td>
<td><input type="text" id="suppid" name="suppid"></td>
</tr><tr>
<td>Category ID:</td>
<td><input type="text" id="catid" name="catid"></td>
</tr><tr>
<td>Quantity of Stock:</td>
<td><input type="text" id="quantity" name="quantity"></td>
</tr><tr>
<td>Unit Price:</td>
<td><input type="text" id="unitprice" name="unitprice"></td>
</tr><tr>
<td>Unit Stock:</td>
<td><input type="text" id="unitstock" name="unitstock"></td>
</tr><tr>
<td>Units On Order:</td>
<td><input type="text" id="unitorder" name="unitorder"></td>
</tr><tr>
<td>Reorder Level:</td>
<td><input type="text" id="reorderlevel" name="reorderlevel"></td>
</tr>
</table>
<br /><br />
<input type="submit" name="submit" id="submit" value="Add New"> 
<input type="reset" name="reset" id="reset" value="Cancel">
</form>

</body>
</html>
Processing page:

<%
Dim strProdid = Trim(Request.Form("prodid"))
Dim strProdname = Trim(Request.Form("prodname"))
Dim strSuppid = Trim(Request.Form("suppid"))
Dim strCatid = Trim(Request.Form("catid"))
Dim strQuantity = Trim(Request.Form("quantity"))
Dim strUnitprice = Trim(Request.Form("unitprice"))
Dim strUnitstock = Trim(Request.Form("unitstock"))
Dim strUnitorder = Trim(Request.Form("unitorder"))
Dim strReorderlevel = Trim(Request.Form("reorderlevel"))

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/Inetpub/wwwroot/northwind.mdb"

sql="INSERT INTO Products (Product_ID,Product_Name,"
sql=sql & "Supplier_ID,Category_ID,Quantity_Per_Unit,Unit_Price,Units_In_Stock,Units_On_Order,Reorder_Level)"
sql=sql & " VALUES "
sql=sql & "'" & strProdid & "',"
sql=sql & "'" & strProdname & "',"
sql=sql & "" & strSuppid & ","
sql=sql & "" & strCatid & ","
sql=sql & "'" & strQuantity & "',"
sql=sql & "'" & strUnitprice & "',"
sql=sql & "" & strunitstock & ","
sql=sql & "" & strUnitorder & ","
sql=sql & "" & strReorderlevel & ")"

'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
%>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP Forum

All times are GMT -4. The time now is 9:02 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC