Jump to content

Recommended Posts

Why are the words causing the switch to die

switch ($page) {
case "1":
include 'explore.php';
break;
case "see":
include 'see.php';
break;
case "kill":
include 'kill.php';
break;
case "2":
include 'inventory.php';
break;
case "3":
include 'guilds.php';
break;
default:
echo "entry";
}

Link to comment
https://forums.phpfreaks.com/topic/268829-switch-pulling-wrong-page/
Share on other sites

<?php
/* this defaulting to see.php
*/
if (isset($_GET["action"])){
$action = $_GET["action"];
echo "act" . $action;
} else {
$action=0;
}
switch ($action) {
case "see":
include 'see.php';
break;
case "kill":
include 'kill.php';
break;
default:
include 'explore_main.php';
}
?>

Took a while but solved it somehow by setting a negative case value outside of the data bounds:

<?php
if (isset($_GET["action"])){
$action = $_GET["action"];
echo "act" . $action;
} else {
$action=-10;
}
switch ($action) {
case "see":
include 'see.php';
break;
case "kill":
include 'kill.php';
break;
default:
include 'explore_main.php';
break;
}
?>

You're using "page" in the URL, but you're asking for $_GET['action']. That's your real problem.

The fact that it defaulted to "see.php" is because 0 == 'see', due to the way type auto casting works.

Edited by Christian F.

Christian is right.

 

You're also using a lot of buzzwords that make no sense. PHP scripts are not applets. There's no such thing as a "data bounds." And you need to read up on how PHP handles comparisons between data types

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.