Jump to content

switch statement doesn't work on Mac


skateme

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/68443-switch-statement-doesnt-work-on-mac/
Share on other sites

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";
}

}

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.