ericburnard Posted October 4, 2008 Share Posted October 4, 2008 Hi the. Its been a good few years since i last played around with coding anything, and i decided the other day to see what i could come up with again. But ive hit a problem. Could you tell me if the following code is allowed. Ive split the IF function up so that the elseif can be repeated as many times as it needs to. Here is the code: <? include ('db.php'); ob_start(); $cookie=$_COOKIE["d_login"]; mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM deptabs WHERE dep='$cookie'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); if($_GET['page']==logoff){ header('location: http://ericburnard.freehostia.com/logoff.php'); } $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $tab=mysql_result($result,$i,"tab"); $link=mysql_result($result,$i,"link"); $dep=mysql_result($result,$i,"dep"); elseif ($_GET ==$id){ header('location: http://ericburnard.freehostia.com/$link'); } $i++; } else { echo "Sorry Page Not Found"; } ob_end_flush(); ?> And here is the error im getting: Parse error: parse error, unexpected T_ELSEIF in /home/www/ericburnard.freehostia.com/test.php on line 31 Pointers in the right direction would be awesome. Chears Eric x Quote Link to comment Share on other sites More sharing options...
papaface Posted October 4, 2008 Share Posted October 4, 2008 if($_GET['page']==logoff){ should be if($_GET['page']=="logoff"){ Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 4, 2008 Share Posted October 4, 2008 Your code is a bit muddled. You close the if, then open a while loop, then try and do an elseif. Can't be done, you need to do some re-arranging. Quote Link to comment Share on other sites More sharing options...
ericburnard Posted October 4, 2008 Author Share Posted October 4, 2008 Your code is a bit muddled. You close the if, then open a while loop, then try and do an elseif. Can't be done, you need to do some re-arranging. Are you saying its not possible to do what im trying to do?? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 4, 2008 Share Posted October 4, 2008 In the manner you are attempting it isn't. Your code doesn't make sense. I'm just guessing but try this out: <?php include ('db.php'); ob_start(); $cookie=$_COOKIE["d_login"]; mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM deptabs WHERE dep='$cookie'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); if($_GET['page'] == "logoff"){ header('location: http://ericburnard.freehostia.com/logoff.php'); exit; }else{ $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $tab=mysql_result($result,$i,"tab"); $link=mysql_result($result,$i,"link"); $dep=mysql_result($result,$i,"dep"); if($_GET['page'] == $id){ header("Location: http://ericburnard.freehostia.com/{$link}"); exit; } $i++; } //If it got here, then display the page not found. echo "Sorry Page Not Found"; ob_end_flush(); ?> [/code[ Quote Link to comment Share on other sites More sharing options...
ericburnard Posted October 4, 2008 Author Share Posted October 4, 2008 In the manner you are attempting it isn't. Your code doesn't make sense. I'm just guessing but try this out: <?php include ('db.php'); ob_start(); $cookie=$_COOKIE["d_login"]; mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM deptabs WHERE dep='$cookie'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); if($_GET['page'] == "logoff"){ header('location: http://ericburnard.freehostia.com/logoff.php'); exit; }else{ $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $tab=mysql_result($result,$i,"tab"); $link=mysql_result($result,$i,"link"); $dep=mysql_result($result,$i,"dep"); if($_GET['page'] == $id){ header("Location: http://ericburnard.freehostia.com/{$link}"); exit; } $i++; } //If it got here, then display the page not found. echo "Sorry Page Not Found"; ob_end_flush(); ?> [/code[ I gave that a go but got unexpected $ as an error which is only the closing bracket of the php ?> Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 4, 2008 Share Posted October 4, 2008 Yeah my bad, try this: <?php include ('db.php'); ob_start(); $cookie=$_COOKIE["d_login"]; mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM deptabs WHERE dep='$cookie'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); if($_GET['page'] == "logoff"){ header('location: http://ericburnard.freehostia.com/logoff.php'); exit; }else{ $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $tab=mysql_result($result,$i,"tab"); $link=mysql_result($result,$i,"link"); $dep=mysql_result($result,$i,"dep"); if($_GET['page'] == $id){ header("Location: http://ericburnard.freehostia.com/{$link}"); exit; } $i++; } } //If it got here, then display the page not found. echo "Sorry Page Not Found"; ob_end_flush(); ?> Quote Link to comment Share on other sites More sharing options...
ericburnard Posted October 4, 2008 Author Share Posted October 4, 2008 Ok ive tried that. When p go to ?page=1 i get if(1==logoff){ header('location: http://ericburnard.freehostia.com/logoff.php'); } else { echo 'Sorry Page Not Found' } For every other page number i get sorry page not found. Ive deleted my cookies loged in again as admin (admin pages are 3 and 4), and when i go on pages 3 and 4 i still get "sorry page not found". At least there is no error this time Quote Link to comment Share on other sites More sharing options...
ericburnard Posted October 4, 2008 Author Share Posted October 4, 2008 ok i have taken the exit bit ot from here if($_GET['page'] == $id){ header("Location: http://ericburnard.freehostia.com/{$link}"); exit; } It dosnt work when i go to the page but when i refresh the page it will load the right page. Any ideas anyone?? 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.