phpRoshan Posted May 8, 2007 Share Posted May 8, 2007 Hi ther, Im working on a admin page, what i wanted to do was when a user clicks on a submit button, admin page should veryfy which button was clicked and acroding to clicked button user should be redirected to a different page. So i did that using following codes. switch(isset($_POST)) { case (isset($_POST['artistadmin'])): header("location:artist.php"); case (isset($_POST['categoryadmin'])): header("location:categories.php"); case (isset($_POST['mmfileadmin'])): header("location:mmediafile.php"); default: $objAdmin->showAdminOption(); } It worked fine only for the first cliced button.But after reruring to the main admin page when the second button was clicked still it redirected to the same page. i dont know how to make changes for this hedder function in order to work properly. Can anybody tell how to solve this prob? or any other alternative way to do the same thig? Quote Link to comment https://forums.phpfreaks.com/topic/50503-solved-problems-with-redirecting-pageshelp-pls/ Share on other sites More sharing options...
taith Posted May 8, 2007 Share Posted May 8, 2007 you need to be careful with headers, you want to "exit;" right after any/all of them... Quote Link to comment https://forums.phpfreaks.com/topic/50503-solved-problems-with-redirecting-pageshelp-pls/#findComment-248125 Share on other sites More sharing options...
soycharliente Posted May 8, 2007 Share Posted May 8, 2007 You should also use a break statement whenever you use switch statements. Quote Link to comment https://forums.phpfreaks.com/topic/50503-solved-problems-with-redirecting-pageshelp-pls/#findComment-248127 Share on other sites More sharing options...
phpRoshan Posted May 8, 2007 Author Share Posted May 8, 2007 Exactly!! It works perfect with "Break" statment. Thanks for ur help mate!! Quote Link to comment https://forums.phpfreaks.com/topic/50503-solved-problems-with-redirecting-pageshelp-pls/#findComment-248128 Share on other sites More sharing options...
taith Posted May 8, 2007 Share Posted May 8, 2007 in most cases... yes... break; should be used for switch()es... as this is only doing one specific task, they arnt necessary, if you exit; ...but it is good coding practice... Quote Link to comment https://forums.phpfreaks.com/topic/50503-solved-problems-with-redirecting-pageshelp-pls/#findComment-248130 Share on other sites More sharing options...
phpRoshan Posted May 8, 2007 Author Share Posted May 8, 2007 I checked with "Exit" statment it too works well!! Thanks for the hint mate..! Quote Link to comment https://forums.phpfreaks.com/topic/50503-solved-problems-with-redirecting-pageshelp-pls/#findComment-248133 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.