• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 498
  • Last Modified:

DW8 ASP VB :Insert repeating region items in a form into a database

DW8 ASP VB and MDB:
I have created a form, which consists of information for a product just added into my db. The rows are a repeating region with a hidden fields for the product id, colour and sze, and then a text field for insertion of quantity. I need the hidden fields and the quantity to be inserted into my 'stock' table. So for example the product is availablein small medium and large and in blue and yellow.

I have everything working ok, but can't get the final insert to work. I'm think it may need a 'for each' statement of some sort but haven't been able to find a way that works, and there doesn't seem to be an insert or update record function in DW that does the job.

Thanks for your help:

The code for the formis:

      <form ACTION="<%=MM_editAction%>" METHOD="POST" name="frmaddproduct" id="frmaddproduct">
      <%
While ((Repeat1__numRows <> 0) AND (NOT RsStock.EOF))
%>
        <table width="460" cellspacing="5" cellpadding="5">
          <tr>
            <td width="130"><input name="frmprodid" type="hidden" id="frmprodid" value="<%=(RsStock.Fields.Item("ProdProdID").Value)%>" />
              <input name="frmsizeid" type="hidden" id="frmsizeid" value="<%=(RsStock.Fields.Item("SizeGroupID").Value)%>" />
              <%=(RsStock.Fields.Item("SizeName").Value)%></td>
              <td width="174"><input name="frmcolourid" type="hidden" id="frmcolourid" value="<%=(RsStock.Fields.Item("AvailColourID").Value)%>" />
                <%=(RsStock.Fields.Item("AvailColourName").Value)%></td>
              <td width="61">Quantity:</td>
              <td width="146"><label>
                <input name="frmquantity" type="text" id="frmquantity" value="10" size="5" maxlength="10" />
              </label></td>
            </tr>
        </table>
        <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  RsStock.MoveNext()
Wend
%>
<p>
          <label>
          <input type="submit" name="Submit2" value="Update" />

And my insert (MM_Edit in DW*) is

If (CStr(Request("MM_insert")) = "frmaddproduct") Then
  If (Not MM_abortEdit) Then
    ' execute the insert
        Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_MagicalRooms_STRING
    MM_editCmd.CommandText = "INSERT INTO Stock (StockProdID, StockSizeID, StockColourID, Quantity) VALUES (?, ?, ?, ?)"
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("frmprodid"), Request.Form("frmprodid"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("frmsizeid"), Request.Form("frmsizeid"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 5, 1, -1, MM_IIF(Request.Form("frmcolourid"), Request.Form("frmcolourid"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 5, 1, -1, MM_IIF(Request.Form("frmquantity"), Request.Form("frmquantity"), null)) ' adDouble
    MM_editCmd.Execute
      MM_editCmd.ActiveConnection.Close

0
swordfishsoup
Asked:
swordfishsoup
  • 10
  • 10
  • 7
1 Solution
 
RouchieCommented:
Before I try answer this, are you saying that you want to cycle down through the populated table and add a database row to the STOCK database table FOR EACH row where the frmquantity field has been given a value?

If so, this is much more advanced logic than DW is capable of dealing with.  I've never tried it in ASP either so it will be an interesting thing to tackle...!!
0
 
swordfishsoupAuthor Commented:
:) Glad you find it interesting, it's been driving me crazy!

I think you have understood what I'm trying to do.
In plain speaking:
On the 'addproduct ' page I add ''shirt' then description, select 'small-med-large' from size group, and add colours of blue and green.
This info is added to the relevant tables. At the end of this (adding images etc) a page is generated that creates repeating regions in a table with a quantity 'input' at the end of each row, like:
SHIRT:
SML BLUE Quantity= "input"
MED BLUE Quantity= "input"
LGE BLUE Quantity= "input"
SML GREEN Quantity= "input"
MED GREEN Quantity= "input"
LGE GREEN Quantity= "input"

Each row has a hidden field of 'colourID' 'sizeID' and 'productID' for inserting into STOCK

SO... On 'submit' the rows in the 'STOCK' table would have 'colourID' 'sizeID' and 'productID' and Quantity

I hope that makes sense? As I'm writing I'm wondering if I can add the details to the STOCK table at the time of submitting the initial info, and then retrive it later and update quantities using the straight 'insert record behaviour', I'll look into that, I may be approaching this backwards!

If you do have any ideas that would be great.

I did wonder if I could have an ID of some kind for the row of the form that increases in value by one on each repeat and then in the 'insert' statement have a ' for each 'thing' in form insert ''colourID' 'sizeID' and 'productID' and Quantity, then the next, although I don't know how to do this?

Thanks for taking the trouble to look at this,look forward to your views.

Best wishes
Dave
0
 
RouchieCommented:
>> I did wonder if I could have an ID of some kind for the row of the form that increases in value by
>> one on each repeat and then in the 'insert' statement have a ' for each 'thing' in form insert
>> ''colourID' 'sizeID' and 'productID' and Quantity

ASP.NET can do this natively, but sadly classic ASP can't, so we have to suffer lots of extra code :-(

The whole loop thing is possible but a little messy.  The easiest and most secure way to achieve a good solution would be, as you say, to add the stock details earlier on.  The recommended solution would be to use a database stored procedure (SP), instead of a single INSERT command in Dreamweaver.  

SP's can perform multiple operations in one go, which make them ideal for larger operations.  I only write SP's using SQL Server, and don't use Access/mySQL, so if you're using them I can't really help out other than do the ASP loop thing.  If you're using SQL Server on the other hand, then you're in business!

Let me know either way...!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
swordfishsoupAuthor Commented:
Hi Rouchie

Thanks for that. Well I seem to be using the most incompatible combination...ASP VB and Access. Part of me is wondering if I should switch to ASP.NET, even though I'm half (well quarter) way through the project and on a deadline which is looming oh too quickly!

I'll see if I can add this stuff further back up the line and I'll investigate using SP's with this although haven't touched on those yet...look out Google here I come...

If you have any more thoughts or advice about the rather crazy notion of switching to ASP.NET....I am a fast and rather stubborn learner so I do wonder if it might be worth while. Is ASP.NET via DW8 ok, or would using visual web developer be a better option in your opinion? I am quite familiar with DW wheras the Visual studio stuff is still a bit alien to me.

Thanks again
Have a good evening

Dave
0
 
Jason C. LevineNo oneCommented:
>> Is ASP.NET via DW8 ok,

Nope.  You would need to move to Visual Studio to take full advantage of ASP.NET.

As soon as Rouchie sees this, he will cut and paste his DW/ASP.NET manifesto that is fast becoming famous here.

There may be another way to achieve this but Rouchie will need to help on the coding.  In PHP, you can submit arrays of fields in the POST operation if your form has this notation:

<input name="frmprodid[]" etc etc etc>

The [] force the form values into an array which can then be stepped through with a for-each or do-while construct.  I'm not sure if ASP will handle that, but it should.

In any event, you are definitely going to be beyond the canned behaviors in DW.  Welcome to real programming.

J

0
 
swordfishsoupAuthor Commented:
Thanks Jason..very reassuring!! :)

As I collapsed into the bed last night with my head spinning it dawned on me that I couldn't switch on this project even if I wanted to as the shopping cart software I have bought for this isn't available in ASP.NET. So I am confined to the dark world that is ASP VB. There must be a more logical/simple way to achieve this....

I shall have a fresh look today.

I keep coming bak to the notion that if I could have an incrementing ID (be it div, hidden field??) on each row of the repeating region part of the form, I could then loop through them to insert...can a div/class be a variable?

Have good days

Dave
0
 
Jason C. LevineNo oneCommented:
>> incrementing ID (be it div, hidden field??) on each row of the repeating region part of the form, I could then loop
>> through them to insert.

Well, this is basically the same thing as submitting in an array.  You use the ASP VB functions to find out how many elements are in the array and loop through from element 0 to element X performing the insert operation.

Interestingly enough, it looks like a similar question is in process:

http://www.experts-exchange.com/Web_Development/Software/Macromedia_Dreamweaver/Q_22877498.html
0
 
RouchieCommented:
>> As soon as Rouchie sees this, he will cut and paste his DW/ASP.NET manifesto that is fast
>> becoming famous here.

I'll save it for another time given that its not possible for Dave to adopt, but I'm already looking forward to the next time I get to use it...

>> Well, this is basically the same thing as submitting in an array

ASP won't natively submit an array, but according to ryancys in the other question, you can name more than 1 form item with the same name, which the form then collects into a comma-seperated array on the receiving page.
My problem comes with the fact that it would break if somebody used a comma when completing the form.  I can't see how to remove this other than by using client-side validation.  
I have however thought up an alternative approach using a simple integer loop to name the form fields in each row, then use the same loop to gather the submitted data.

Can you post the entire page code so I can add this logic in for you?

0
 
swordfishsoupAuthor Commented:

Hi Rouchie

The full page of code is below.

Just to make an already complicated scenario just a bit more complicated...I have realised that as some products don't have a 'size' and 'colour' I'm going to need to include some 'Is not nothing' kind of thing also...aren't I? So that just the quanity the single item will be entered into STOCK.

I think I'm learning a valuable lesson about the planing stage of a project like this..

Dave

<%@LANGUAGE="VBSCRIPT"%>  
<% OPTION EXPLICIT %>

<!--#include file="Connections/MagicalRooms.asp" -->
<%
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
%>
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
  If condition = "" Then
    MM_IIf = ifFalse
  Else
    MM_IIf = ifTrue
  End If
End Function
%>
<%
If (CStr(Request("MM_insert")) = "frmaddproduct") Then
  If (Not MM_abortEdit) Then
    ' execute the insert
         Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_MagicalRooms_STRING
    MM_editCmd.CommandText = "INSERT INTO Stock (StockProdID, StockSizeID, StockColourID, Quantity) VALUES (?, ?, ?, ?)"
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("frmprodid"), Request.Form("frmprodid"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("frmsizeid"), Request.Form("frmsizeid"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 5, 1, -1, MM_IIF(Request.Form("frmcolourid"), Request.Form("frmcolourid"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 5, 1, -1, MM_IIF(Request.Form("frmquantity"), Request.Form("frmquantity"), null)) ' adDouble
    MM_editCmd.Execute
      MM_editCmd.ActiveConnection.Close

    ' append the query string to the redirect URL
    Dim MM_editRedirectUrl
    MM_editRedirectUrl = "default.asp"
    If (Request.QueryString <> "") Then
      If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
        MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
      Else
        MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
      End If
    End If
    Response.Redirect(MM_editRedirectUrl)
  End If
End If
%>
<%
Dim RsSearch
Dim RsSearch_cmd
Dim RsSearch_numRows

Set RsSearch_cmd = Server.CreateObject ("ADODB.Command")
RsSearch_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsSearch_cmd.CommandText = "SELECT ProdName FROM tblProducts"
RsSearch_cmd.Prepared = true

Set RsSearch = RsSearch_cmd.Execute
RsSearch_numRows = 0
%>
<%
Dim RsStock__MMColParam
RsStock__MMColParam = "131"
If (Request.QueryString("frmprodid")     <> "") Then
  RsStock__MMColParam = Request.QueryString("frmprodid")    
End If
%>
<%
Dim RsStock
Dim RsStock_cmd
Dim RsStock_numRows

Set RsStock_cmd = Server.CreateObject ("ADODB.Command")
RsStock_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsStock_cmd.CommandText = "SELECT AvailColourName, ProdProdID, AvailColourID, ProdAvailColour, ProdSizeGroup, SizeName, SizeGroupID, ProdName, ProdShortDesc FROM tblAvailColours, tblProdColours, tblProducts, tblSizeGroup WHERE ProdID = ? AND ProdProdID = ProdID AND AvailColourID = ProdAvailColour AND ProdSizeGroup = SizeGroup"
RsStock_cmd.Prepared = true
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param1", 5, 1, -1, RsStock__MMColParam) ' adDouble

Set RsStock = RsStock_cmd.Execute
RsStock_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
RsStock_numRows = RsStock_numRows + Repeat1__numRows
%>
<%
'  *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

Dim RsStock_total
Dim RsStock_first
Dim RsStock_last

' set the record count
RsStock_total = RsStock.RecordCount

' set the number of rows displayed on this page
If (RsStock_numRows < 0) Then
  RsStock_numRows = RsStock_total
Elseif (RsStock_numRows = 0) Then
  RsStock_numRows = 1
End If

' set the first and last displayed record
RsStock_first = 1
RsStock_last  = RsStock_first + RsStock_numRows - 1

' if we have the correct record count, check the other stats
If (RsStock_total <> -1) Then
  If (RsStock_first > RsStock_total) Then
    RsStock_first = RsStock_total
  End If
  If (RsStock_last > RsStock_total) Then
    RsStock_last = RsStock_total
  End If
  If (RsStock_numRows > RsStock_total) Then
    RsStock_numRows = RsStock_total
  End If
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them

If (RsStock_total = -1) Then

  ' count the total records by iterating through the recordset
  RsStock_total=0
  While (Not RsStock.EOF)
    RsStock_total = RsStock_total + 1
    RsStock.MoveNext
  Wend

  ' reset the cursor to the beginning
  If (RsStock.CursorType > 0) Then
    RsStock.MoveFirst
  Else
    RsStock.Requery
  End If

  ' set the number of rows displayed on this page
  If (RsStock_numRows < 0 Or RsStock_numRows > RsStock_total) Then
    RsStock_numRows = RsStock_total
  End If

  ' set the first and last displayed record
  RsStock_first = 1
  RsStock_last = RsStock_first + RsStock_numRows - 1
 
  If (RsStock_first > RsStock_total) Then
    RsStock_first = RsStock_total
  End If
  If (RsStock_last > RsStock_total) Then
    RsStock_last = RsStock_total
  End If

End If
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/master1.dwt.asp" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable -->
<link href="magicalroomsadmin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --><!-- InstanceParam name="bag" type="boolean" value="false" -->

</head>

<body onload="MM_preloadImages('img/images/wish_list_selected_03.gif','img/images/log_in_selected_03.gif','img/images/register_selected_03.gif','img/images/delivery_selected_03.gif','img/images/locator_selected_03.gif','img/images/help_selected_03.gif','img/images/voucher_selected_03.gif')">
<div id="container">
<div id="banner">
<div id="logo"></div>
<div id="tel">
  <div id="quicksearch">
    <form id="frmsearch" name="frmsearch" method="post" action="">
      <img src="img/key_search.gif" width="119" height="21" />
      <input name="txtsearch" type="text" id="txtsearch" size="30" />
      <input name="Submit" type="image" value="Submit" src="img/images/go_04.gif" alt="Search" />
       
    </form>
  </div>
</div>
<div id="tabs"><img src="img/images/full_tabs_03.gif" name="fulltabs" width="467" height="23" border="0" usemap="#tab" id="fulltabs" />
<map name="tab" id="tab">
  <area shape="rect" coords="2,2,56,21" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/wish_list_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
  <area shape="rect" coords="58,3,97,21" href="add_product.asp" onmouseover="MM_swapImage('fulltabs','','img/images/log_in_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
  <area shape="rect" coords="99,3,146,21" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/register_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
  <area shape="rect" coords="149,3,196,23" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/delivery_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
  <area shape="rect" coords="200,3,316,22" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/locator_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
  <area shape="rect" coords="319,5,350,22" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/help_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
  <area shape="rect" coords="355,5,455,21" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/voucher_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
</map></div>
</div>

<div id="mainpage">
<div id="leftnav">
<script type="text/javascript" language="JavaScript" src="Scripts/drop.js">
      </script>
 <!--#include file="nav.asp" -->
    </div>
    <!-- InstanceBeginEditable name="contentarea" -->
    <p>&nbsp;</p>
    <div id="content">
      <h2>Please add stock levels for <%=(RsStock.Fields.Item("ProdName").Value)%> <%=(RsStock.Fields.Item("ProdShortDesc").Value)%> <br />
        or submit with the default level. You will be notified when stock drops to 5 items.</h2>
      <form ACTION="<%=MM_editAction%>" METHOD="POST" name="frmaddproduct" id="frmaddproduct">
      <%
While ((Repeat1__numRows <> 0) AND (NOT RsStock.EOF))
%>
        <table width="460" cellspacing="5" cellpadding="5">
          <tr>
            <td width="130"><input name="frmprodid" type="hidden" id="frmprodid" value="<%=(RsStock.Fields.Item("ProdProdID").Value)%>" />
              <input name="frmsizeid" type="hidden" id="frmsizeid" value="<%=(RsStock.Fields.Item("SizeGroupID").Value)%>" />
              <%=(RsStock.Fields.Item("SizeName").Value)%></td>
              <td width="174"><input name="frmcolourid" type="hidden" id="frmcolourid" value="<%=(RsStock.Fields.Item("AvailColourID").Value)%>" />
                <%=(RsStock.Fields.Item("AvailColourName").Value)%></td>
              <td width="61">Quantity:</td>
              <td width="146"><label>
                <input name="frmquantity" type="text" id="frmquantity" value="10" size="5" maxlength="10" />
              </label></td>
            </tr>
        </table>
        <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  RsStock.MoveNext()
Wend
%>
<p>
          <label>
          <input type="submit" name="Submit2" value="Update" />
          </label>
        </p>
      
           
   

     
<input type="hidden" name="MM_insert" value="frmaddproduct">
    </form>
      
    <br />
    <br />
    <br />
<br />
<br />

      </div>
    <!-- InstanceEndEditable --></div>
<div class="footer" id="footer"><a href="page.html">How To Find Us</a>  <a href="page.html">Terms  &amp; Conditions</a>  - <a href="page.html">Privacy
    Policy</a> - Returns - Links - Customer Feedback<br />
  &copy; Copyright Magical Rooms 2007</div>
</div>
</body>
<!-- InstanceEnd --></html>
<%
RsSearch.Close()
Set RsSearch = Nothing
%>
<%
RsStock.Close()
Set RsStock = Nothing
%>
0
 
Jason C. LevineNo oneCommented:
>> ASP won't natively submit an array, but according to ryancys in the other question, you can name more than 1
>> form item with the same name, which the form then collects into a comma-seperated array on the receiving page.

Really?  Wow, that sucks.
0
 
RouchieCommented:
>> Really?  Wow, that sucks.

Yep.  How does your array submission look in the HTML form when rendered?

Thankfully in ASP there are ways around the problem.  Sadly I am out of the office until monday now so can't provide you with any explicit code details.  Sorry about that.

Please have a look at my final post in this question though.  As Jason pointed out earlier the logic is very similar.  Instead of having a defined number of rows, you could loop through your first piece of code and generate the fields required, each named normally followed by an increasing number (i.e. frmquantity1, frmquantity2, frmquantity3 etc...)
http:/Q_22877498.html#20047136
0
 
Jason C. LevineNo oneCommented:
>> Yep.  How does your array submission look in the HTML form when rendered?

Huh?  
0
 
swordfishsoupAuthor Commented:
>> Yep.  How does your array submission look in the HTML form when rendered?

I'm confused too?
0
 
Jason C. LevineNo oneCommented:
The worst part is he might be out until Monday, so we're going to have to wait in suspense.
0
 
RouchieCommented:
>> Yep.  How does your array submission look in the HTML form when rendered?

You say that PHP supports array submission, so how does that end up looking in HTML?  In ASP if you get lots of form fields with the same name, i.e.

<input type="text" name="myText" value="Some Value" />
<input type="text" name="myText" value="Some Value" />
<input type="text" name="myText" value="Some Value" />

and then submit it, in the submitted data it looks like this:
myText = "Some Value, Some Value, Some Value"

So you then have to split the comma-riddled string into an array, which is problematic if the string contains commas.  So, how does it differ in PHP?  Is it a similar process or more refined and less prone to errors?  Although I won't be learning PHP, it's still useful to know a bit about it I guess...!
0
 
RouchieCommented:
Right here is my version of your code.  Please note that you have a LOT of code to try to understand, and I also have no way to test it out without the database, so have patience and let me know if you see any errors so I can fix them for you!

The logic is as follows:
1 - instead of simply creating the update quantity form, cycle through the rows and generate a new set of form fields for each database row returned.
2 - keep a count of the number of rows generated and store this value in a hidden field at the end of the form
3 - when the form is submitted, read this hidden value back then loop through the correct number of rows, reading the value from each row of controls, and saving each one

-----------------------------------------------------------------------------------------------------------

<%@LANGUAGE="VBSCRIPT"%>  
<% OPTION EXPLICIT %>

<!--#include file="Connections/MagicalRooms.asp" -->
<%
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
%>
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
  If condition = "" Then
    MM_IIf = ifFalse
  Else
    MM_IIf = ifTrue
  End If
End Function
%>
<%
If (CStr(Request("MM_insert")) = "frmaddproduct") Then
  If (Not MM_abortEdit) Then
    ' execute the insert
    Dim MM_editCmd
    Dim rowsToInsert
    rowsToInsert = cint(request.Form("rowcounter"))
   
    For i = 0 to rowsToInsert
            Set MM_editCmd = Server.CreateObject ("ADODB.Command")
            MM_editCmd.ActiveConnection = MM_MagicalRooms_STRING
            MM_editCmd.CommandText = "INSERT INTO Stock (StockProdID, StockSizeID, StockColourID, Quantity) VALUES (?, ?, ?, ?)"
            MM_editCmd.Prepared = true
            MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("frmprodid" & i), Request.Form("frmprodid" & i), null)) ' adDouble
            MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("frmsizeid" & i), Request.Form("frmsizeid" & i), null)) ' adDouble
            MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 5, 1, -1, MM_IIF(Request.Form("frmcolourid" & i), Request.Form("frmcolourid" & i), null)) ' adDouble
            MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 5, 1, -1, MM_IIF(Request.Form("frmquantity" & i), Request.Form("frmquantity" & i), null)) ' adDouble
            MM_editCmd.Execute
            MM_editCmd.ActiveConnection.Close
            Set MM_editCmd = Nothing
      Next

    ' append the query string to the redirect URL
    Dim MM_editRedirectUrl
    MM_editRedirectUrl = "default.asp"
    If (Request.QueryString <> "") Then
      If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
        MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
      Else
        MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
      End If
    End If
    Response.Redirect(MM_editRedirectUrl)
  End If
End If
%>
<%
Dim RsSearch
Dim RsSearch_cmd
Dim RsSearch_numRows

Set RsSearch_cmd = Server.CreateObject ("ADODB.Command")
RsSearch_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsSearch_cmd.CommandText = "SELECT ProdName FROM tblProducts"
RsSearch_cmd.Prepared = true

Set RsSearch = RsSearch_cmd.Execute
RsSearch_numRows = 0
%>
<%
Dim RsStock__MMColParam
RsStock__MMColParam = "131"
If (Request.QueryString("frmprodid")     <> "") Then
  RsStock__MMColParam = Request.QueryString("frmprodid")    
End If
%>
<%
Dim RsStock
Dim RsStock_cmd
Dim RsStock_numRows

Set RsStock_cmd = Server.CreateObject ("ADODB.Command")
RsStock_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsStock_cmd.CommandText = "SELECT AvailColourName, ProdProdID, AvailColourID, ProdAvailColour, ProdSizeGroup, SizeName, SizeGroupID, ProdName, ProdShortDesc FROM tblAvailColours, tblProdColours, tblProducts, tblSizeGroup WHERE ProdID = ? AND ProdProdID = ProdID AND AvailColourID = ProdAvailColour AND ProdSizeGroup = SizeGroup"
RsStock_cmd.Prepared = true
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param1", 5, 1, -1, RsStock__MMColParam) ' adDouble

Set RsStock = RsStock_cmd.Execute
RsStock_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
RsStock_numRows = RsStock_numRows + Repeat1__numRows
%>
<%
'  *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

Dim RsStock_total
Dim RsStock_first
Dim RsStock_last

' set the record count
RsStock_total = RsStock.RecordCount

' set the number of rows displayed on this page
If (RsStock_numRows < 0) Then
  RsStock_numRows = RsStock_total
Elseif (RsStock_numRows = 0) Then
  RsStock_numRows = 1
End If

' set the first and last displayed record
RsStock_first = 1
RsStock_last  = RsStock_first + RsStock_numRows - 1

' if we have the correct record count, check the other stats
If (RsStock_total <> -1) Then
  If (RsStock_first > RsStock_total) Then
    RsStock_first = RsStock_total
  End If
  If (RsStock_last > RsStock_total) Then
    RsStock_last = RsStock_total
  End If
  If (RsStock_numRows > RsStock_total) Then
    RsStock_numRows = RsStock_total
  End If
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them

If (RsStock_total = -1) Then

  ' count the total records by iterating through the recordset
  RsStock_total=0
  While (Not RsStock.EOF)
    RsStock_total = RsStock_total + 1
    RsStock.MoveNext
  Wend

  ' reset the cursor to the beginning
  If (RsStock.CursorType > 0) Then
    RsStock.MoveFirst
  Else
    RsStock.Requery
  End If

  ' set the number of rows displayed on this page
  If (RsStock_numRows < 0 Or RsStock_numRows > RsStock_total) Then
    RsStock_numRows = RsStock_total
  End If

  ' set the first and last displayed record
  RsStock_first = 1
  RsStock_last = RsStock_first + RsStock_numRows - 1
 
  If (RsStock_first > RsStock_total) Then
    RsStock_first = RsStock_total
  End If
  If (RsStock_last > RsStock_total) Then
    RsStock_last = RsStock_total
  End If

End If
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/master1.dwt.asp" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable -->
<link href="magicalroomsadmin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --><!-- InstanceParam name="bag" type="boolean" value="false" -->

</head>

<body onload="MM_preloadImages('img/images/wish_list_selected_03.gif','img/images/log_in_selected_03.gif','img/images/register_selected_03.gif','img/images/delivery_selected_03.gif','img/images/locator_selected_03.gif','img/images/help_selected_03.gif','img/images/voucher_selected_03.gif')">
<div id="container">
<div id="banner">
<div id="logo"></div>
<div id="tel">
  <div id="quicksearch">
    <form id="frmsearch" name="frmsearch" method="post" action="">
      <img src="img/key_search.gif" width="119" height="21" />
      <input name="txtsearch" type="text" id="txtsearch" size="30" />
      <input name="Submit" type="image" value="Submit" src="img/images/go_04.gif" alt="Search" />
       
    </form>
  </div>
</div>
<div id="tabs"><img src="img/images/full_tabs_03.gif" name="fulltabs" width="467" height="23" border="0" usemap="#tab" id="fulltabs" />
<map name="tab" id="tab">
  <area shape="rect" coords="2,2,56,21" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/wish_list_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
  <area shape="rect" coords="58,3,97,21" href="add_product.asp" onmouseover="MM_swapImage('fulltabs','','img/images/log_in_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
  <area shape="rect" coords="99,3,146,21" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/register_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
  <area shape="rect" coords="149,3,196,23" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/delivery_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
  <area shape="rect" coords="200,3,316,22" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/locator_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
  <area shape="rect" coords="319,5,350,22" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/help_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
  <area shape="rect" coords="355,5,455,21" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/voucher_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
</map></div>
</div>

<div id="mainpage">
<div id="leftnav">
<script type="text/javascript" language="JavaScript" src="Scripts/drop.js">
      </script>
 <!--#include file="nav.asp" -->
    </div>
    <!-- InstanceBeginEditable name="contentarea" -->
    <p>&nbsp;</p>
    <div id="content">
      <h2>Please add stock levels for <%=(RsStock.Fields.Item("ProdName").Value)%> <%=(RsStock.Fields.Item("ProdShortDesc").Value)%> <br />
        or submit with the default level. You will be notified when stock drops to 5 items.</h2>
      <form ACTION="<%=MM_editAction%>" METHOD="POST" name="frmaddproduct" id="frmaddproduct">
      <table width="460" cellspacing="5" cellpadding="5">
      <%
      Dim rowCounter
      rowCounter = 0
While ((Repeat1__numRows <> 0) AND (NOT RsStock.EOF))
%>
      <tr>
            <td width="130">
                  <input name="frmprodid<%=rowcounter%>" type="hidden" id="frmprodid" value="<%=(RsStock.Fields.Item("ProdProdID").Value)%>" />
                  <input name="frmsizeid<%=rowcounter%>" type="hidden" id="frmsizeid" value="<%=(RsStock.Fields.Item("SizeGroupID").Value)%>" />
                  <%=(RsStock.Fields.Item("SizeName").Value)%>
            </td>
            <td width="174">
                  <input name="frmcolourid<%=rowcounter%>" type="hidden" id="frmcolourid" value="<%=(RsStock.Fields.Item("AvailColourID").Value)%>" />
                  <%=(RsStock.Fields.Item("AvailColourName").Value)%>
            </td>
            <td width="61">
                  Quantity:
            </td>
            <td width="146">
                  <input name="frmquantity<%=rowcounter%>" type="text" id="frmquantity" value="10" size="5" maxlength="10" />
            </td>
      </tr>
        <%
  rowCounter = rowCounter + 1
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  RsStock.MoveNext()
Wend
%>
</table>
<p>
            <input type="hidden" name="rowcounter" value="<%=rowCounter%>" />
          <label>
          <input type="submit" name="Submit2" value="Update" />
          </label>
        </p>
     
           
   

     
<input type="hidden" name="MM_insert" value="frmaddproduct">
    </form>
     
    <br />
    <br />
    <br />
<br />
<br />

      </div>
    <!-- InstanceEndEditable --></div>
<div class="footer" id="footer"><a href="page.html">How To Find Us</a>  <a href="page.html">Terms  &amp; Conditions</a>  - <a href="page.html">Privacy
    Policy</a> - Returns - Links - Customer Feedback<br />
  &copy; Copyright Magical Rooms 2007</div>
</div>
</body>
<!-- InstanceEnd --></html>
<%
RsSearch.Close()
Set RsSearch = Nothing
%>
<%
RsStock.Close()
Set RsStock = Nothing
%>
0
 
Jason C. LevineNo oneCommented:
>> You say that PHP supports array submission, so how does that end up looking in HTML?

Yes, you have lots of fields with the same name, but they also get an array id.

<input name="frmprodid[]" type="text">

The posted value is called like so:

$_POST["Company"]["$i"]

where $i is set to be the array key.  0,1,2,3, etc.  All you do in the processing code is set up a loop that looks like this:

    if( array_key_exists("ArrayID", $_POST) && is_array($_POST["ArrayID"]))
    {
         for( $i = 0; $i < count( $_POST["ArrayID"] ); $i++ ) {

                  do something;

}

n.b. I always set a dynamic variable in the HTML form that starts at 0 and counts up with the repeat region.  ArrayID is the variable in this case.
0
 
RouchieCommented:
Jason, that seems like quite a handy feature.  In a strictly geek way its interesting just how much the two languages compare.

Anyway Dave, how are you getting on with that code??
0
 
swordfishsoupAuthor Commented:
Hi Rouchie/Jason

I have beern away for the weekend and have just picked up these couple of posts. Rouchie - thanks for taking so much time and trouble to help me out on this, much more than I expected.

So I am back at my desk, sleeves rolled up, crash helmet on and I'm going in.....

Will feedback on this as I go aong

Thanks again

Dave
0
 
RouchieCommented:
Ah, I'm glad I'm not the only ASP developer to wear a crash helmet... ;-)
0
 
swordfishsoupAuthor Commented:
Oh yes....safety first. My wife gets a bit concerned about the fluoresent jacket though! :)
0
 
swordfishsoupAuthor Commented:
Hi Rouchie
I'm getting this:
Variable is undefined: 'i'
/MR07test/add_stock.asp, line 35
Could this be that the variabiable doesn't have a value at this point?

And what does 'cint' mean in this?
 Dim rowsToInsert
    rowsToInsert = cint(request.Form("rowcounter"))
   
    For i = 0 to rowsToInsert

I can see from the error that this working, splitting and numbering the rows:

frmprodid0=131&frmsizeid0=1&frmcolourid0=1&frmquantity0=10&frmprodid1=131&frmsizeid1=2&frmcolourid1=1&frmquantity1=10&frmprodid2=131&frmsizeid2=3 ETC...

So is looking good

Thanks
0
 
RouchieCommented:
>> Variable is undefined: 'i'

This means I've started to use a variable that doesn't exist at this point.  Sometimes I forget I'm not programming ASP.NET (which doesn't require everything to be defined in advance for loops).

Go to Line 34 in the code:

-----------------------------------------------------------------------------------------------------------
For i = 0 to rowsToInsert
-----------------------------------------------------------------------------------------------------------

and change it to say this, so we declare the variable before using it to count with:

-----------------------------------------------------------------------------------------------------------
Dim i
For i = 0 to rowsToInsert
-----------------------------------------------------------------------------------------------------------

>> And what does 'cint' mean in this?

CInt means "convert to integer".  By default the querystring/form post data is sent to the next page as a string value, which means it is pure text.  We can't do math functions on text (i.e. the counting loop), so we have to convert the text value into a math value.  For example, "5" becomes 5

It sounds an odd concept but isn't too difficult once you see it happen a few times.
0
 
swordfishsoupAuthor Commented:
If we were at the pub I'd buy you a great big beer!!

Excellent. Problem solved. I still have to adapt it slightly as there wil be occasions when there is no colour or size, just the product ID and quantity. I'll have a go at fathoming this one out. I reckon it's going to be a 'if stock is not nothing' then else kind of thing. But that is another question I suppose.

So thanks for all your help Rouchie. This is the begining of this project and I have the whole nightmare of getting this thing to work as an online store...and time is running out.....so keep your crash helmet on standy as I may be back.. very soon...

Have a great day and thanks again

Dave

 
0
 
RouchieCommented:
>> there wil be occasions when there is no colour or size, just the product ID and quantity

This depends on what you want to store in the database when this occurs, or what you want to display on-screen, but yes your guess is correct at what would happen.

>> If we were at the pub I'd buy you a great big beer!!

Well that depends on where the pub is.  Offers of beer or more valuable than expert points...!!
0
 
swordfishsoupAuthor Commented:
Just when you thought it was safe to put your feet up!!

Pub's in Surrey, so will have to wait till I venture up North some day for that one.

I've hit a problem...I've posted it as a seperate question here: http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_22899542.html

It's the lack of colour and size issue (that I so boldly thought I'd be able to sort out) that has got me.

I'm not asking for your help on this one, but as you were so involved in 'part 1' thought I should let you know there was a part two!

Best wishes

Dave
0
 
Jason C. LevineNo oneCommented:
See my comment over there.  
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 10
  • 10
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now