Perad Posted October 25, 2006 Share Posted October 25, 2006 This is my first switch statement and it isn't working. It is supposed to process the values in my form and change the $players value accordingly. Right now it returns 1 no matter what i select.Could someone have a look at it and tell me where i am going wrong.Cheers[code]<form id="form1" name="form1" method="post" action=""> <select name="matchsize"> <option>1v1</option> <option>2v2</option> <option>3v3</option> <option>4v4</option> <option>5v5</option> <option>6v6</option> <option>7v7</option> <option>8v8</option> <option>9v9</option> <option>10v10</option> <option>11v11</option> <option>12v12</option> </select> <input type="submit" name="submit1" value="Save Changes" /></form><?php function NumberOfPlayers() { $players = 0; if (isset($_POST['submit1'])) { switch(isset($_POST['matchsize'])) { case '1v1': $players = 1; break; case '2v2': $players = 2; break; case '3v3': $players = 3; break; case '4v4': $players = 4; break; case '5v5': $players = 5; break; case '6v6': $players = 6; break; case '7v7': $players = 7; break; case '8v8': $players = 8; break; case '9v9': $players = 9; break; case '10v10': $players = 10; break; case '11v11': $players = 11; break; case '12v12': $players = 12; break; default: $players = 0; } echo $players; }} NumberOfPlayers(); [/code] Link to comment https://forums.phpfreaks.com/topic/25054-resolved-problem-with-switch-statement/ Share on other sites More sharing options...
trq Posted October 25, 2006 Share Posted October 25, 2006 You need to remove the isset() from within the switch() argument. Test it first, eg;[code=php:0]if (isset($_POST['matchsize'])) { switch($_POST['matchsize']) { // rest of code }}[/code]PS: Whatever editor your using is terrible for cut and paste. Link to comment https://forums.phpfreaks.com/topic/25054-resolved-problem-with-switch-statement/#findComment-114202 Share on other sites More sharing options...
Perad Posted October 25, 2006 Author Share Posted October 25, 2006 Magic, thx mate Link to comment https://forums.phpfreaks.com/topic/25054-resolved-problem-with-switch-statement/#findComment-114203 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.