Glese Posted December 12, 2011 Share Posted December 12, 2011 <td > <form action="" method="post"> <b> <?php echo $likes_count; ?> </b> <b> | </b> <b> <?php echo $dislikes_count; ?> </b> <button class="LikeButton" type="submit" name="likes" value="+1">Likes</button> <button class="DislikeButton" type="submit" name="dislikes" value="-1">Dislikes</button> <input type="hidden" name="hidden_con_id" value="<?php echo $con_id; ?>" /> </form> <?php echo $con_id; ?> </td> I have a table with a voting system and the problem I am experiencing is that the hidden id, which I call the hidden contribution id is not set thus the numeric array changes. I know that it is not best practice to use a numeric array for this, though I learned that afterwards. This is the array: // POST BUTTONS inside the table if (isset($_POST['likes'])) { $likes = $_POST['likes']; } if (isset($_POST['dislikes'])) { $dislikes = $_POST['dislikes']; } if (isset($_POST['likes']) || isset($_POST['dislikes'])) { $hidden_con_id = $_POST['hidden_con_id']; } // $array = array ($likes, $dislikes, $con_id, $user_id); if (isset($likes)) { $array[] = $likes; } if (isset($dislikes)) { $array[] = $dislikes; } if (isset($hidden_con_id)) { $array[] = $hidden_con_id; } if (isset($dnuser_id)) { $array[] = $dnuser_id; } As said the problem I have is that the hidden_con_id variable is not set and that consequently array[2] becomes the user_id variable. Any suggestions why it is not becoming set? Quote Link to comment Share on other sites More sharing options...
Glese Posted December 13, 2011 Author Share Posted December 13, 2011 Any suggestions? Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 13, 2011 Share Posted December 13, 2011 I'm not understanding the problem. If the variable is not set, then set it. I have no idea what that value is supposed to be or why it is not set in your code. YOU have put that variable in your code - so why are you not setting it? But, even if the value is not set, there should still be a posted value of a null string. I don't think your problem is the hidden variable - it is the fact that you can only click one button - so the other one is not part of the POST data. Instead of trying to work around a problem that shouldn't even exist, why don't you fix your processing code to NOT store the values in an array with no way to logically know what value is what? If you are going to store these values in an array, at least do it with named indexes. This is all you need to store the POST values in an array. If any POST values are missing a value of false will be stored for that index. //Populate array based on POST data $array = array(); $array['likes'] = (isset($_POST['likes'])) ? $_POST['likes'] : false; $array['dislikes'] = (isset($_POST['dislikes'])) ? $_POST['dislikes'] : false; $array['hidden_con_id'] = (isset($_POST['hidden_con_id'])) ? $_POST['hidden_con_id'] : false; $array['dnuser_id'] = (isset($_POST['dnuser_id'])) ? $_POST['dnuser_id'] : false; Quote Link to comment 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.