nirvana4lf Posted July 29, 2007 Share Posted July 29, 2007 I was trying to run a switch statement with open url and its not working. the statement runs correctly when the variable is embedded in the script. i'm running this from a home computer with XAMPP (comes with Apache 2.2 and PHP 5.2.3 among other things). Whats the problem here? Does it have something to do with Apache or PHP? Thanks. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 30, 2007 Share Posted July 30, 2007 When you say "open URL", you mean your retrieving a value from the URL using $_GET, correct? Post your code, I will test it on my XAMPP and see if I can get it working. Quote Link to comment Share on other sites More sharing options...
nirvana4lf Posted July 30, 2007 Author Share Posted July 30, 2007 no i guess im using the wrong term. here is what i mean (i found this code from an old band site i had to see if i was just doing something wrong and i wasnt): <?php function sam() { echo "<center><h1>Band Members</h1></center><br><br>"; echo "<center><h2>Sam - Guitar</h2></center><br><br>"; echo "<a href=\"switch_test.php\">Back</a>"; } function marc() { echo "<center><h1>Band Members</h1></center><br><br>"; echo "<center><h2>Marc - Guitar</h2></center><br><br>"; echo "<a href=\"switch_test.php\">Back</a>"; } function jordan() { echo "<center><h1>Band Members</h1></center><br><br>"; echo "<center><h2>Jordan - Vocals and Bass</h2></center><br><br>"; echo "<a href=\"switch_test.php\">Back</a>"; } function jake() { echo "<center><h1>Band Members</h1></center><br><br>"; echo "<center><h2>Jake - Drums</h2></center><br><br>"; echo "<a href=\"switch_test.php\">Back</a>"; } function BandMembers() { echo "<center><h1>Band Members</h1></center><br><br><br><br>"; echo "<a href=\"switch_test.php?func=sam\">Sam H.</a><br><br>"; echo "<a href=\"switch_test.php?func=marc\">Marc F.</a><br><br>"; echo "<a href=\"switch_test.php?func=jordan\">Jordan B.</a><br><br>"; echo "<a href=\"switch_test.php?func=jake\">Jake S.</a>"; } switch($func) { default: BandMembers(); break; case "sam": sam(); break; case "marc": marc(); break; case "jordan": jordan(); break; case "jake": jake(); break; } ?> I also have a domain with SBC Yahoo! and this script works there but not on my server at home. Sounds like a configuration problem? Quote Link to comment Share on other sites More sharing options...
nirvana4lf Posted July 30, 2007 Author Share Posted July 30, 2007 sorry forgot to say that what i meant by URL is that the script doesnt work on MY server when i do something like script.php?func=something. it just does to the default case. but it runs correctly on my sbc yahoo server. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 30, 2007 Share Posted July 30, 2007 You probably have Registered_Globals on on one server, and off on the others. Do this: <?php $func = $_GET['func']; function sam() { echo "<center><h1>Band Members</h1></center><br><br>"; echo "<center><h2>Sam - Guitar</h2></center><br><br>"; echo "<a href=\"switch_test.php\">Back</a>"; } function marc() { echo "<center><h1>Band Members</h1></center><br><br>"; echo "<center><h2>Marc - Guitar</h2></center><br><br>"; echo "<a href=\"switch_test.php\">Back</a>"; } function jordan() { echo "<center><h1>Band Members</h1></center><br><br>"; echo "<center><h2>Jordan - Vocals and Bass</h2></center><br><br>"; echo "<a href=\"switch_test.php\">Back</a>"; } function jake() { echo "<center><h1>Band Members</h1></center><br><br>"; echo "<center><h2>Jake - Drums</h2></center><br><br>"; echo "<a href=\"switch_test.php\">Back</a>"; } function BandMembers() { echo "<center><h1>Band Members</h1></center><br><br><br><br>"; echo "<a href=\"switch_test.php?func=sam\">Sam H.</a><br><br>"; echo "<a href=\"switch_test.php?func=marc\">Marc F.</a><br><br>"; echo "<a href=\"switch_test.php?func=jordan\">Jordan B.</a><br><br>"; echo "<a href=\"switch_test.php?func=jake\">Jake S.</a>"; } switch($func) { default: BandMembers(); break; case "sam": sam(); break; case "marc": marc(); break; case "jordan": jordan(); break; case "jake": jake(); break; } ?> Quote Link to comment Share on other sites More sharing options...
nirvana4lf Posted July 30, 2007 Author Share Posted July 30, 2007 that didn't make a difference... how can i turn on Registered_Globals? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 30, 2007 Share Posted July 30, 2007 By the way, you can make a single function that will replace all the individual band members functions. Just do this: <?php function memberInfo($name, $position){ echo "<center><h1>Band Members</h1></center><br><br>"; echo "<center><h2>$name - $position</h2></center><br><br>"; echo "<a href=\"switch_test.php\">Back</a>"; } ?> Then to call the function, you would just do this: memberInfo("Sam", "Guitar"); Just a suggestion, not sure if it will work with what your trying to do. Quote Link to comment Share on other sites More sharing options...
nirvana4lf Posted July 30, 2007 Author Share Posted July 30, 2007 wait, now it works... weird. thanks for the idea, but im not using it in this context. this is just some old script i found that i knew applied to what i'm doing right now. thank you very much! By the way, you can make a single function that will replace all the individual band members functions. Just do this: <?php function memberInfo($name, $position){ echo "<center><h1>Band Members</h1></center><br><br>"; echo "<center><h2>$name - $position</h2></center><br><br>"; echo "<a href=\"switch_test.php\">Back</a>"; } ?> Then to call the function, you would just do this: memberInfo("Sam", "Guitar"); Just a suggestion, not sure if it will work with what your trying to do. 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.