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

}

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.