euel Posted March 24, 2012 Share Posted March 24, 2012 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.. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/259612-getting-wrong-_post-value/ Share on other sites More sharing options...
requinix Posted March 24, 2012 Share Posted March 24, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/259612-getting-wrong-_post-value/#findComment-1330693 Share on other sites More sharing options...
euel Posted March 24, 2012 Author Share Posted March 24, 2012 ah, now it make sense to me.. thank you for pointing that simple thing to me! really appreciated.. tried it and worked.. now i just need to get what values goes to where.. >.< Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/259612-getting-wrong-_post-value/#findComment-1330697 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.