Bisa Posted October 23, 2008 Share Posted October 23, 2008 I'm tired, and thus I am probably overlooking something here... any way, my index.php looks like this: //Secure the get variables and forces them to be integers only $typ = (int) secureFormInput($_GET["typ"]); $mat = (int) secureFormInput($_GET["mat"]); $do = (int) secureFormInput($_GET["do"]); echo $typ . ' typ index <br />'; //Checks what the user wants to do based on the get variables if ($do >= 1) { if ($do == 1) include("om.php"); elseif ($do == 3) include ("kontakt.php"); } elseif ($typ >= 1) include("produkter.php"); else echo "Välkommen, bläddra gärna bland våra smycken i menyn till vänster."; If go to the page using the url /index.php?typ=99 it does not include the produkter.php as I want it to do but I know by the echo $typ . ' typ index <br />'; that $typ is equal to 99. What am I missing here, any pointers to help out would be appreciated. Link to comment https://forums.phpfreaks.com/topic/129834-solved-typ-equals-99-but-if-typ-99-does-not-work-pointers-please/ Share on other sites More sharing options...
discomatt Posted October 23, 2008 Share Posted October 23, 2008 If $do >= 1, the elseif and the else won't ever get executed. Link to comment https://forums.phpfreaks.com/topic/129834-solved-typ-equals-99-but-if-typ-99-does-not-work-pointers-please/#findComment-673076 Share on other sites More sharing options...
Bisa Posted October 23, 2008 Author Share Posted October 23, 2008 thing is, when I use /index.php?typ=99 there is no &do=3 or whatever number, it's not set thus would become 0 and be skipped by $do >= 1 or am I wrong? Edit* Explanation: There is no value in $_GET['do'] hence $do = (int) secureFormInput($_GET["do"]); would set $do equals 0 Link to comment https://forums.phpfreaks.com/topic/129834-solved-typ-equals-99-but-if-typ-99-does-not-work-pointers-please/#findComment-673082 Share on other sites More sharing options...
discomatt Posted October 23, 2008 Share Posted October 23, 2008 Have you echo'ed $do to verify this? Try performing a var_dump on $typ as well, just to be extra sure. Are ANY files included? Or does it make it to the 'else' clause? Link to comment https://forums.phpfreaks.com/topic/129834-solved-typ-equals-99-but-if-typ-99-does-not-work-pointers-please/#findComment-673091 Share on other sites More sharing options...
Bisa Posted October 23, 2008 Author Share Posted October 23, 2008 echoing $do confirms my suspicion that $do equals 0 and no, it does not get as far as else since the only thing I see on the screen is 99 typ index 0 do index (just to make sure I added echo "hello world"; at the beginning of produkter.php but nothing was printed) Edit* var_dump($typ) and $do returns int(99) and int(0) Link to comment https://forums.phpfreaks.com/topic/129834-solved-typ-equals-99-but-if-typ-99-does-not-work-pointers-please/#findComment-673095 Share on other sites More sharing options...
discomatt Posted October 23, 2008 Share Posted October 23, 2008 This blows my mind. Can i see the script in it's entirety? Does it include files if you set $do to an int greater than 1? Link to comment https://forums.phpfreaks.com/topic/129834-solved-typ-equals-99-but-if-typ-99-does-not-work-pointers-please/#findComment-673106 Share on other sites More sharing options...
discomatt Posted October 23, 2008 Share Posted October 23, 2008 Notices aside, the following code works perfectly on my system. <?php $typ = (int) $_GET['typ']; $mat = (int) $_GET['mat']; $do = (int) $_GET['do']; if ($do >= 1) { if ($do == 1) echo 'include("om.php")'; elseif ($do == 3) echo 'include ("kontakt.php")'; } elseif ($typ >= 1) echo 'include("produkter.php")'; else echo "Välkommen, bläddra gärna bland våra smycken i menyn till vänster."; ?> Link to comment https://forums.phpfreaks.com/topic/129834-solved-typ-equals-99-but-if-typ-99-does-not-work-pointers-please/#findComment-673111 Share on other sites More sharing options...
Bisa Posted October 23, 2008 Author Share Posted October 23, 2008 That code works for me as well as I get the echo printed about including, and yes, using the url /index.php?do=x will successfully include om.php or kontakt.php .... this is just weird ??? (I checked the file name on produkter.php just to make sure but yea the file exists and has that name) Link to comment https://forums.phpfreaks.com/topic/129834-solved-typ-equals-99-but-if-typ-99-does-not-work-pointers-please/#findComment-673129 Share on other sites More sharing options...
discomatt Posted October 23, 2008 Share Posted October 23, 2008 And all error reporting is turned on? error_reporting( E_ALL ); Link to comment https://forums.phpfreaks.com/topic/129834-solved-typ-equals-99-but-if-typ-99-does-not-work-pointers-please/#findComment-673133 Share on other sites More sharing options...
Bisa Posted October 23, 2008 Author Share Posted October 23, 2008 yea, added your line and ran the script again with no results (not even notices, should I add other error lines as well?) Link to comment https://forums.phpfreaks.com/topic/129834-solved-typ-equals-99-but-if-typ-99-does-not-work-pointers-please/#findComment-673138 Share on other sites More sharing options...
discomatt Posted October 23, 2008 Share Posted October 23, 2008 ini_set('display_errors', '1'); If you're calling the page as page.php?typ=3 you should be seeing undefined index notices. Link to comment https://forums.phpfreaks.com/topic/129834-solved-typ-equals-99-but-if-typ-99-does-not-work-pointers-please/#findComment-673141 Share on other sites More sharing options...
Bisa Posted October 23, 2008 Author Share Posted October 23, 2008 thank god I included the config file on each page pretty much, in the config file I have the secure form function, the problem with this was when I load index.php I defined the function, when I then included produkter.php I did a new include of config and thus tried to define the function again -> FATAL ERROR! u learn something new every day, sorry to take your time with this, I'll make sure to have errors enabled from now on Link to comment https://forums.phpfreaks.com/topic/129834-solved-typ-equals-99-but-if-typ-99-does-not-work-pointers-please/#findComment-673155 Share on other sites More sharing options...
discomatt Posted October 23, 2008 Share Posted October 23, 2008 Perfect. To get around your issue, check out include_once() or require_once() Link to comment https://forums.phpfreaks.com/topic/129834-solved-typ-equals-99-but-if-typ-99-does-not-work-pointers-please/#findComment-673180 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.