Jump to content

Recommended Posts

Hi Guys

 

Maybe you can help. Im working with an array in my php script and need to pass the entire array through a form. Here is the script. Take a look and tell me if you can see my mistake.

 

I create a dynamic entry screen that has multiple values that I would like to update and want to place them all into an array to update them. At the mo no values are being posted at all.

EG:

 

Entry screen

 

****START FROM*****

 

Update (product1) [  VALUE ]

Update (product2) [ VALUE ]

Update (product2) [ VALUE ]

 

Update All

****** END FORM **************

 

 

Thanks in advance

 

 

*****POST SCRIPT********************

 

$trans = array();

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

            {         

                                                $trans[] = $_POST['max_value[]'];

            }

                                                foreach($trans as $view)

                                                {

                                                            echo "LETS TRY AGAIN : $view <br>";

                                                }

 

************UPDATE SCRIPT******************

 

Have not written this yet until I see that all the correct values are being passed through the array.

 

***********************OUTSIDE FORM****************************************

 

$max_value = array();

**********************INSIDE FORM************************

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

{

<input type="text" name="<? echo "max_value[$i]"; ?>" value="<? echo "$cur_markup"; ?>">

}

 

 

Thank You

 

Link to comment
https://forums.phpfreaks.com/topic/52303-solved-php-array/
Share on other sites

your $_POST array notation is off - when you name an input as an array, it actually forms an array in the $_POST data:

 

$_POST['max_value'][0] => the value from the first input named 'max_value[]'

 

i haven't analysed your whole block of code, but i trust that's where the issue lies.  just run a foreach() on $_POST['max_value'] to grab all the values entered.

Link to comment
https://forums.phpfreaks.com/topic/52303-solved-php-array/#findComment-258039
Share on other sites

You can try this:

 

**********************INSIDE FORM************************

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

{

<input type="text" name="array_values[<? echo "$max_value[$i]"; ?>]" value="<? echo "$cur_markup"; ?>">

}

 

so that the name parameter will be "array_values[0]", "array_values[1]", "array_values[2]", ens.

Where for example ids is:

  0    => Hardware

  1    => Software

  2    => Consumables

 

Let's say the values you input for the form is:

  0    => 5

  1    => 6

  2    => 8

 

Then when you get the the Post value it will be "$_POST['array_values']" which will already be an array, so if you want to set it equal to another empty value just say:

  $the_array =  $_POST['array_values'];

 

When go through the array with:

  foreach ($the_array as $key => $value) {

      echo "$key => $value <br>";

  }

 

You'll get the result of:

 

  0    => 5

  1    => 6

  2    => 8

 

Link to comment
https://forums.phpfreaks.com/topic/52303-solved-php-array/#findComment-258104
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.