Jump to content

getting wrong $_POST value


euel

Recommended Posts

Hi guys! I need your help..

I'm having a problem in getting the post values from my form,

I have 2 arrays and some values:

$total = 3;
$array1 = (branch1, branch2, branch3);
$array2 = (100, 200, 300);
$count = count($array1) - $total;

then i combine them

$array3 = combine_array($array1, $array2);

if $count is 0, using a foreach loop i echo each value and key

foreach($combined_array as $value => $key)
{
echo "<tr>";	

	echo "<td><input type='hidden' name='branch' value='{$value}'></td>";	
        echo "<td id='edit'>" . "<input type='submit' name='edit' value='' />" . "</td>";
	echo "<td id='sep'> / </td>";
	echo "<td><input type='hidden' name='id' value='{$key}'></td>";
	echo "<td id='del'>" . "<input type='submit' name='delete' value='' />" . "</td>";

very simple and it works perfectly fine,

but  if the variable $count is not equal to 0, i append both arrays(1 & 2) so that it will be equal to 0. (data appended is not important i just need them for the table output.)

for($i = 0; $i < $count; $i++)
{
     $array1[] = "null" . $i;
     $array2[] = $i;
}
// then combine
    $array3 = combine_array($array1, $array2);

// echo each value and key
foreach($combined_array as $value => $key)
{
echo "<tr>";	

	echo "<td><input type='hidden' name='branch' value='{$value}'></td>";	
        echo "<td id='edit'>" . "<input type='submit' name='edit' value='' />" . "</td>";
	echo "<td id='sep'> / </td>";
	echo "<td><input type='hidden' name='id' value='{$key}'></td>";
	echo "<td id='del'>" . "<input type='submit' name='delete' value='' />" . "</td>";
       echo "</tr>";

i tried to view the code souce and both hidden fields contain correct data but if i tried to delete/edit it doesn't work.

i tried echoing/print_r the $_POST['branch'] & $_POST['id'] after i click on delete/edit and it always gives me the last $value and $key of the combined array for all the submit buttons..

 

Any thoughts?

As i said the appended data is not important but the problem is once i click delete  the original values in array1 and 2 are not what post is giving me..therefore i cannot delete or edit them..

Sorry if my post is too long.. :D

Thanks in advance!

 

 

 

Link to comment
Share on other sites

PHP doesn't support multiple values from inputs with the same name. You will only get the last value as each one overwrites the previous value.

 

You can, however, use arrays. Name your inputs like branch[] (yes, like PHP's array syntax) and $_POST["branch"] will be an array. You can use array keys too like branch[0] or branch[foo] if you wish but they're not required.

Link to comment
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.