ekante Posted April 18, 2009 Share Posted April 18, 2009 So the thing is i need to create manager/pilot web based sistem, where users register as manager or pilot. The whole idea is that when thay register in DB is there status pilot or manager. concept: *)user log's in *)function check the status *)page redirects him to pilots or manager control panel, where he is doing all his nececery things, stuff =D *)but when he attempts to go in ther control page liek manager is going in pilots page , function is not redirecting but just opening managers control panel again. But pilots and manager pages are different from each other. Thing is , i have no clue how to write the code for function like that , i need some hints doing this , some advice ,and some sample code to understand youre idea. Best regardrs. Quote Link to comment Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 Can you post the code that isn't working please? Quote Link to comment Share on other sites More sharing options...
ekante Posted April 18, 2009 Author Share Posted April 18, 2009 Problem is that i dont know how to write the code, so i didnt even start to write, because i dont know where to start. but i think like this: function userStatus() { $query = "SELECT * FROM user WHERE userid = '$userid' "; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); if ($row['status'] = 'user') { //dont know how the redirect code works } else if ($row['status'] = 'manager') { //same } else if ($row['status'] = 'pilot') { //same } } Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 18, 2009 Share Posted April 18, 2009 change your single '=' to double '==' .. you do this when checking against a value .. kind of like saying, "is equal to" .. a single = is like saying, "equals". for redirection .. i bet if you typed 'php redirection' in google you'd have your problem solved already .. look into the header() function .. it's what you're going to need .. but, before using header(), look into how to use it, otherwise, you're going to get an error message along the lines of "Headers already sent...", and you're going to be right back here. a simple header redirect would look something like this : header("Location: http://www.mysite.com"); exit; where mysite.com is your site. Quote Link to comment Share on other sites More sharing options...
ekante Posted April 18, 2009 Author Share Posted April 18, 2009 Ok that function is working good, but how do i make that function auto start when i open the page? Quote Link to comment Share on other sites More sharing options...
stickynote427 Posted April 18, 2009 Share Posted April 18, 2009 I'm probably wrong, but it should automatically perform, if it isn't in any "if" statements, etc. As long as it is contained only in the <?php and ?> tags, I think it should do it automatically. Quote Link to comment Share on other sites More sharing options...
ekante Posted April 18, 2009 Author Share Posted April 18, 2009 i have problem with header(), he allway sends me to 1.php when i type index.php?id= {random from 1-3} <?php /*$query = "SELECT * FROM user WHERE userid = '$userid' "; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result);*/ if ($id = 1) { header("Location: http://localhost/1.php"); } else if ($id = 2) { header("Location: http://localhost/2.php"); } else if ($id = 3) { header("Location: http://localhost/3.php"); } ?> <?php echo "you stay here"; ?> how can i do redirection or just "send" to another page anotherway, i think this is very silly way to do that, or in case there isnt tell me where im wrong. Quote Link to comment Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 That is how you do redirection. I can see two immeditate things wrong with your code. Your "=" should be "==" to test for a value and also $id is never being set to the value of $_GET['id'] Quote Link to comment Share on other sites More sharing options...
Axeia Posted April 18, 2009 Share Posted April 18, 2009 You most likely want to use include instead of a redirect, as redirects would mean 2 page requests opposed to one. so something like one of the two examples below and then having the a user/manager/pilot .php file in the same directory as the file with this code is in. <?php function userStatus() { $query = "SELECT * FROM user WHERE userid = '$userid' "; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); if ($row['status'] == 'user') { include( 'user.php' ); } else if ($row['status'] == 'manager') { include( 'manager.php' ); } else if ($row['status'] == 'pilot') { include( 'pilot.php' ); } } ?> Alternatively use: <?php function userStatus() { $query = "SELECT * FROM user WHERE userid = '$userid' "; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); switch( $row['status'] ) { case 'user': case 'manager': case 'pilot': include( $row['status'].'.php' ); } } ?> 2nd example is easier to maintain, but might be harder to read to you.. go with whatever you feel comfortable with. Quote Link to comment Share on other sites More sharing options...
ekante Posted April 18, 2009 Author Share Posted April 18, 2009 Thanks guys here is simple code for (localhost/index.php?id=1 or 2 or 3): <?php /*$query = "SELECT * FROM user WHERE userid = '$userid' "; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result);*/ $_GET['id']; /*$query = "SELECT * FROM user WHERE userid = '$userid' "; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result);*/ if ($id = 1) { include( '1.php' ); } else if ($id = 2) { include( '2.php' ); } else if ($id = 3) { include( '3.php' ); } ?> I got what i wanted thanks. Best regards. Quote Link to comment Share on other sites More sharing options...
Axeia Posted April 18, 2009 Share Posted April 18, 2009 Strange how it's solved as you're still using = instead of == so you'll always be getting the same results. a single = is used for ASSIGNING values. == is used for COMPARING values. 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.