BluwAngel Posted March 5, 2012 Share Posted March 5, 2012 okay i have table named ZAMJENE with 2 rows only row that i need to setup is named id_zamjena and have values 15 and 16 when i do echo on page it work great but when i press button i get only 16 for both entries full cde is too long so i paste only important parts $query_zamjene = mysql_query ("SELECT * FROM zamjene WHERE id_user_1='$moj_id' AND zamjenjeno='0' ORDER BY id_event_1"); echo "<form method='post' action='event_zamjenjen.php'>"; while ($rows = mysql_fetch_array($query_zamjene)) { $id_zamjena = $rows['id_zamjena']; $id_event_1 = $rows['id_event_1']; $id_event_2 = $rows['id_event_2']; $id_user_2 = $rows['id_user_2']; echo "$id_zamjena"; // THIS ROW WORKS CORRECTLY echo "<input name='id_zamjena' type='hidden' value=$id_zamjena>"; // output of this is always 16 echo "<input name='response' type='submit' value='Prihvati zamjenu' /> <input name='response' type='submit' value='Odbaci zamjenu' /> <br>"; } echo"</form>"; Quote Link to comment https://forums.phpfreaks.com/topic/258328-different-query-for-same-variable/ Share on other sites More sharing options...
premiso Posted March 5, 2012 Share Posted March 5, 2012 echo "<input name='id_zamjena' type='hidden' value='$id_zamjena'>"; Most likely your value is getting screwed up due to lack of quotes, give that a shot. Quote Link to comment https://forums.phpfreaks.com/topic/258328-different-query-for-same-variable/#findComment-1324190 Share on other sites More sharing options...
BluwAngel Posted March 5, 2012 Author Share Posted March 5, 2012 i tried both with and without same problem Quote Link to comment https://forums.phpfreaks.com/topic/258328-different-query-for-same-variable/#findComment-1324192 Share on other sites More sharing options...
ManiacDan Posted March 5, 2012 Share Posted March 5, 2012 When you have multiple inputs of the same name in a form, only the LAST one will be submitted when you submit the form. You must name your input name='id_zamjena[]', then $_POST['id_zamjena'] will be an ARRAY of these inputs. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/258328-different-query-for-same-variable/#findComment-1324195 Share on other sites More sharing options...
BluwAngel Posted March 5, 2012 Author Share Posted March 5, 2012 hm... if i use just echo $_POST['id_zamjena']; it will just say array as output how do i extract same number i stored so i can use it again? if i use id_zamjena[0] i will always get 15, dosnt matter wich button do i press Quote Link to comment https://forums.phpfreaks.com/topic/258328-different-query-for-same-variable/#findComment-1324200 Share on other sites More sharing options...
xyph Posted March 5, 2012 Share Posted March 5, 2012 It's very hard to help you due to a language barrier. I am having troubles even figuring out what you're trying to do. ManiacDan has already told you that using his method will result in an array. If you don't understand how arrays work, you should start there. Since the $_POST variable is an array, it's quite important to understand how it works before using. http://oreilly.com/catalog/progphp/chapter/ch05.html You may want to explain exactly what you're trying to do, we may be able to assist more accurately. Quote Link to comment https://forums.phpfreaks.com/topic/258328-different-query-for-same-variable/#findComment-1324204 Share on other sites More sharing options...
ManiacDan Posted March 5, 2012 Share Posted March 5, 2012 Put your <form> and </form> tags INSIDE your loop, that will solve your problems. Quote Link to comment https://forums.phpfreaks.com/topic/258328-different-query-for-same-variable/#findComment-1324206 Share on other sites More sharing options...
BluwAngel Posted March 5, 2012 Author Share Posted March 5, 2012 you are right Dan it works now... such terrible simple mistake thanks Quote Link to comment https://forums.phpfreaks.com/topic/258328-different-query-for-same-variable/#findComment-1324210 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.