phpnewbie112 Posted November 18, 2007 Share Posted November 18, 2007 Hello, I have 2 fields username and password inside a form + 3 options (member, affiliate and admin) each one has different file (member.php, affiliate.php and admin.php) thus each option have a different post file. how can you do it in php to have 1 form with the mentioned but forwarding to the selected option file. thank you Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 18, 2007 Share Posted November 18, 2007 You can try like this, after your username and password field suppose you have list box from where user will select his type <form id="form1" name="form1" method="post" action="<?=$curPage?>"> <select name="user_type" id="user_type"> <option>----------------------</option> <option value="Affilate">Affilate</option> <option value="Member">Member</option> <option value="Admin">Admin</option> </select> <input type="submit" name="Submit" value="Submit" /> </form> and in the same page you keep this <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { $user_type = $_POST['user_type']; switch ($user_type) { case "Affilate": $curPage = "affilate.php"; break; case "Member": $curPage = "member.php"; break; case "Admin": $curPage = "admin.php"; break; } } ?> Hope, you get the idea. Quote Link to comment Share on other sites More sharing options...
phpnewbie112 Posted November 18, 2007 Author Share Posted November 18, 2007 thanks for the help, I would really appreciate if you can advice what to do in my situation: each file let's take for example: admin.php include variables and all sql procedures to check whether the user/pass are correct. moving these codes into the single file (the one with the form and 3 options) is complicated for me. is there any way I can include them so that when I do a submit it goes to the given file and do the necessary checkups? thanks a million Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 19, 2007 Share Posted November 19, 2007 I think including the file will work... <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { $user_type = $_POST['user_type']; switch ($user_type) { case "Affilate": require_once("affilate.php"); //added here $curPage = "affilate.php"; break; case "Member": require_once("member.php");// here $curPage = "member.php"; break; case "Admin": require_once("admin.php");// and here $curPage = "admin.php"; break; } } ?> Quote Link to comment Share on other sites More sharing options...
phpnewbie112 Posted November 19, 2007 Author Share Posted November 19, 2007 Unfortunately it is not working any alternative method you can advice? thanks Quote Link to comment Share on other sites More sharing options...
phpnewbie112 Posted November 19, 2007 Author Share Posted November 19, 2007 whatever I choose it redirected to the 1st one for example affiliate.php and the include is not working. please advice thanks Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 20, 2007 Share Posted November 20, 2007 This should work now , I tried this index.php <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { $user_type = $_POST['user_type']; switch ($user_type) { case "Affilate": require_once("affilate.php"); echo $var; break; case "Member": require_once("member.php"); echo $var; break; case "Admin": require_once("admin.php"); echo $var; break; } } ?> <table width="474" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="474" height="228" valign="top"><form id="form1" name="form1" method="post"> <select name="user_type" id="user_type"> <option>----------------------</option> <option value="Affilate">Affilate</option> <option value="Member">Member</option> <option value="Admin">Admin</option> </select> <input type="submit" name="Submit" value="Submit" /> </form><!--DWLayoutEmptyCell--> </td> </tr> </table> And in affilate.php, member.php and admin.php keep this code <?php // just change the string in all 3 pages ADMIN, MEMBER and AFFILATE $var = "You are in ADMIN page"; ?> Quote Link to comment Share on other sites More sharing options...
phpnewbie112 Posted November 20, 2007 Author Share Posted November 20, 2007 it worked by forwarding to the page but witout login :'(, the values entered in the username and password field are simply ignored and thus cannot login yet. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 20, 2007 Share Posted November 20, 2007 What do you mean by forwarding ??? Can you post your code ? Quote Link to comment Share on other sites More sharing options...
phpnewbie112 Posted November 20, 2007 Author Share Posted November 20, 2007 I mean if I choose affilate.php it open the affilate pages but what I want is to be opened and perform the validation of the username and password thus if the user/pass are correct it moves to the management page. the page affilate.php already have a part for login as well as the other pages. My question is to merge all these logins in one page with select option... Quote Link to comment Share on other sites More sharing options...
phpnewbie112 Posted November 20, 2007 Author Share Posted November 20, 2007 Thank you I fixed the issue, I added a post for the user and password too. thanks 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.