1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Rep Power
    I am trying to pass the form two form elements as an array to a script that will display and update a DB entry. The array gets passed..ie..qty1, aty2, etc...but I am unable to access the array in the process script unless I use literals...temp=qty1 instead of temp=qty[$ctr]; The code that sends the arrays is as follows... (Method =post)

    while ($myrow = mysql_fetch_array($cart)){ //while
    $number = $myrow[item_no];
    $result = mysql_query("SELECT * FROM shoot_prod where item_no='$number'");
    echo ("<tr><td width=1%><input type=text size=2 maxlength=4 name='qty[]' value=".$myrow['qty']."></td>");;
    echo ("<td>".$cart_row['item_name']."</td>");
    echo ("<td>".$cart_row['item_price']."</td></tr>");
    $total = $total + $cart_row['item_price'];
    echo("<input type=hidden name='item_no[]' value=".$myrow['item_no'].">");

    To process, I have the following:
    for ($ctr=1; $ctr <= $cntr; $ctr++){
    echo ("Quantity: ");
    echo $qty[$ctr];
    echo ("<p>Item: ");
    echo $item_no[$ctr];
    echo ("<br>");

    The problem arises in the fact that it doesn't pull the values...it returns empty unless i use qty1...

    Any thoughts.

  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Niagara Falls (On the wrong side of the gorge)
    Rep Power
    A few;

    First $cntr is being started as 1 (as is your loop in the second script) but the first value will be 0. Change the for loop to:

    for ($i=0;$i<$cntr;$i++)

    will solve that. Second, you are not passing $cntr to the second script that I can see. You would have to add:

    echo "<input type=hidden name=cntr value='$cntr'>";

    after the while loop.

    Better yet, just do away with the counter incrementing and use:


    along with the corresponding hidden form element outside of the loop (but inside the <form></form> tags.

    [This message has been edited by rod k (edited June 22, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Rep Power
    Thanks, everything is working really well now. The counters were definitely one problem, and I think the serving was caching a page as well.


Similar Threads

  1. How to loop through arrays and find matching elements
    By aiya in forum HTML Programming
    Replies: 5
    Last Post: February 9th, 2004, 09:35 AM
  2. passing back password fields to form without showing them?
    By ralphuk100 in forum PHP Development
    Replies: 8
    Last Post: February 6th, 2004, 11:00 AM
  3. Replies: 4
    Last Post: January 24th, 2004, 01:09 AM
  4. HTTP Error 400: Bad Request, with basic form
    By crackwombat in forum PHP Development
    Replies: 1
    Last Post: January 23rd, 2004, 06:40 PM
  5. Replies: 8
    Last Post: January 20th, 2004, 08:04 PM

IMN logo majestic logo threadwatch logo seochat tools logo