skateme Posted September 8, 2007 Share Posted September 8, 2007 I downloaded my PHP from entropy.ch and i don't think that the switch statement works. this is my code: <html><head><title>Switch Statements</title></head> <body> Select action: <form action="switch.php?action=edit" method="post"> <input type="submit" name="edit" value="Edit" /><br> </form> <form action="switch.php?action=delete" method="post"> <input type="submit" name="delete" value="Delete" /><br> </form> <form action="switch.php?action=change" method="post"> <input type="submit" name="change" value="Change" /><br> </form> <?php switch($_GET['action']) { case "edit": print "Add edit function"; break; case "delete": print "Add delete function"; break; case "change": print "Add change function"; break; default: print "Please select a button"; break; } ?> </body></html> and when i load the page, all i get is a blank screen. sorry if this is the wrong section and thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/68443-switch-statement-doesnt-work-on-mac/ Share on other sites More sharing options...
marcus Posted September 8, 2007 Share Posted September 8, 2007 Why not use a dropdown? Lol. It looks fine to me. $array = array('edit','delete','change'); if(!$_GET['action'] || !in_array($_GET['action'],$array)){ echo "<form name=\"switch\" method=\"get\" action=\"switch.php\">\n"; echo "Option: <select name=\"action\">\n"; foreach($array AS $options){ echo "<option value=\"$options\">".ucfirst($options)."</option>\n"; } echo "</select> <input type=\"submit\" value=\"Switch Away Captain\"></form>\n"; }else { switch($_GET['action']){ case edit: echo "omfg edit"; break; case delete: echo "omfg delete"; break; case change: echo "omfg change"; break; default: echo "omfg wtf"; } } Quote Link to comment https://forums.phpfreaks.com/topic/68443-switch-statement-doesnt-work-on-mac/#findComment-344113 Share on other sites More sharing options...
skateme Posted September 9, 2007 Author Share Posted September 9, 2007 i'm just learning to use switch statements, so thats why i need to use switch lol. thanks for your help though Quote Link to comment https://forums.phpfreaks.com/topic/68443-switch-statement-doesnt-work-on-mac/#findComment-344556 Share on other sites More sharing options...
Barand Posted September 9, 2007 Share Posted September 9, 2007 try <html><head><title>Switch Statements</title></head> <body> Select action: <form action="switch.php" method="post"> <input type="submit" name="sub" value="Edit" /><br> <!-- submit buttons --> <input type="submit" name="sub" value="Delete" /><br> <!-- same names, different values --> <input type="submit" name="sub" value="Change" /><br> </form> <?php switch($_POST['sub']) { case "Edit": print "Add edit function"; break; case "Delete": print "Add delete function"; break; case "Change": print "Add change function"; break; default: print "Please select a button"; break; } ?> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/68443-switch-statement-doesnt-work-on-mac/#findComment-344651 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.