Suchy Posted April 27, 2009 Share Posted April 27, 2009 How can I pass a variable ( event id) to a different page when a button is pressed? The problem is that the events are listed via a loop, and when I use sessions the event session always contains the id of the last event on the list. The only other way I can think of is adding onclick="window.location.href='login.php?event=<?php echo $id;?> ' and then just pulling the id from the url Is there a different way ?? Quote Link to comment https://forums.phpfreaks.com/topic/155880-solved-passing-variables/ Share on other sites More sharing options...
jackpf Posted April 27, 2009 Share Posted April 27, 2009 What's wrong with that? It's the best way of doing it. See that big url up there? Even this forum does it. Quote Link to comment https://forums.phpfreaks.com/topic/155880-solved-passing-variables/#findComment-820508 Share on other sites More sharing options...
Mchl Posted April 27, 2009 Share Posted April 27, 2009 If it's a button you can use a form with a hidden field for this value. Quote Link to comment https://forums.phpfreaks.com/topic/155880-solved-passing-variables/#findComment-820515 Share on other sites More sharing options...
Suchy Posted April 27, 2009 Author Share Posted April 27, 2009 Wouldn't it be the same as with Sessions, if by each button I had a hidden filed, ex: <input name="event_id" type="hidden" value="<?php echo $id; ?>" /> and if I pressed on a button for example in the middle of the list, the event_id would always be that one of the last element. Quote Link to comment https://forums.phpfreaks.com/topic/155880-solved-passing-variables/#findComment-820611 Share on other sites More sharing options...
jackpf Posted April 27, 2009 Share Posted April 27, 2009 What? If it's in a loop, just assign each input the id relative to the current record/whatever you're looping. Quote Link to comment https://forums.phpfreaks.com/topic/155880-solved-passing-variables/#findComment-820616 Share on other sites More sharing options...
Suchy Posted April 27, 2009 Author Share Posted April 27, 2009 But on the login.php how would I know what to use if the hidden fields are like: <input name="1" type="hidden" value="<?php echo $id; ?>" /> <input name="2" type="hidden" value="<?php echo $id; ?>" /> <input name="3" type="hidden" value="<?php echo $id; ?>" /> <input name="4" type="hidden" value="<?php echo $id; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/155880-solved-passing-variables/#findComment-820621 Share on other sites More sharing options...
Mchl Posted April 27, 2009 Share Posted April 27, 2009 What exactly are you trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/155880-solved-passing-variables/#findComment-820624 Share on other sites More sharing options...
Suchy Posted April 27, 2009 Author Share Posted April 27, 2009 I have a events.php page with a list of events (ex. Word class, Powerpoint class ... ), by each I have a register button. What I want is that when someone hits the register button he will be taken to the login.php page, where it will say something like "To register for event $$$$$ please fill out the form". $$$$$ would be the value of the variable that I want to pass from the previous page. Quote Link to comment https://forums.phpfreaks.com/topic/155880-solved-passing-variables/#findComment-820630 Share on other sites More sharing options...
Mchl Posted April 27, 2009 Share Posted April 27, 2009 And how do you create this list of events? Quote Link to comment https://forums.phpfreaks.com/topic/155880-solved-passing-variables/#findComment-820637 Share on other sites More sharing options...
Suchy Posted April 28, 2009 Author Share Posted April 28, 2009 I used Ajax to call a function to save the sellected event id in a session, that works for me. Dzięki za pomoc Mchl. Quote Link to comment https://forums.phpfreaks.com/topic/155880-solved-passing-variables/#findComment-821041 Share on other sites More sharing options...
Mchl Posted April 28, 2009 Share Posted April 28, 2009 You're welcome. Quote Link to comment https://forums.phpfreaks.com/topic/155880-solved-passing-variables/#findComment-821081 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.