desolati0n Posted October 5, 2007 Share Posted October 5, 2007 Hello, I hope I'm posting this in the correct place. Basically I'm trying to make a page that will let you change the order in which some items are displayed. The problem I'm having is passing back the id value of the item that you want to move up or down in the display order. Here is the code: elseif($op=='editdisplayorder'){ $button = $_POST['button']; $editid = $_POST['id']; if($button == 'Move Up'){ //Move Position up a spot } if($button == 'Move Down'){ //Move Position down a spot } $sql->Query("SELECT id, title, location, posid FROM careers ORDER BY posid"); print " <center> <table border='1' width='60%'><form action='index.php?&op=editdisplayorder' method='post'> <tr bgcolor='#FFFFFF'><th colspan='4'>Open Positions</th></tr> <tr><td><center><b>Position</b></center></td> <td><center><b>Location</b></center></td> <td><center><b>Display Order</b></center></td></tr>"; for($i=0; $i<$sql->rows; $i++){ $sql->Fetch($i); $id = $sql->data[0]; $title = $sql->data[1]; $location = $sql->data[2]; $posid = $sql->data[3]; print "<input type='hidden' name='id' value='$id'> <tr><td><center>$title</center></td> <td><center>$location</center></td> <td><center><input type='submit' name='button' value='Move Up'> <input type='submit' name='button' value='Move Down'></center></td></tr>"; } print "<tr></tr> </form></table> <br><br><br> "; I'm trying to use a hidden input type to pass back the id value of the item (career position) when one of the buttons ('Move Up' or 'Move Down') are selected, but I want the hidden id value to be unique to each button. But instead right now the value of id that is passed back by each button is the same as the last value that id was set to inside the for loop. For example the table looks kind of like this: Career Position 1 [move up] [move down] Career Position 2 [move up] [move down] Career Position 3 [move up] [move down] And I want the "move up" and "move down" buttons for 'Career Position 1' to pass back the id value of 'Career Position 1', but instead it passes the id value of 'Career Position 3'. Any help at all with this would be appreciated, and I hope I explained it clear enough. Thanks, desolati0n Quote Link to comment https://forums.phpfreaks.com/topic/71986-trouble-passing-form-variables/ Share on other sites More sharing options...
logicopinion Posted October 5, 2007 Share Posted October 5, 2007 $button = $_POST['button']; $editid = $_POST['id']; i think $button = $_POST['button']; $editid = $_POST['editid']; or $button = $_POST['button']; $id = $_POST['id']; ??? Quote Link to comment https://forums.phpfreaks.com/topic/71986-trouble-passing-form-variables/#findComment-362599 Share on other sites More sharing options...
GingerRobot Posted October 5, 2007 Share Posted October 5, 2007 Why dont you just use links rather than submit buttons? You can then pass the id in the URL. The reason why you always seem to get the ID of the last item is that all of your hidden fields have the name 'id', hence when you retrieve the value from the GET/POST array, its always the last one. Edit: If you particularly want to use submit buttons, i suggest you use a bit of javascript to update the value of a single hidden field prior to form submission. Quote Link to comment https://forums.phpfreaks.com/topic/71986-trouble-passing-form-variables/#findComment-362600 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.