Jump to content

Archived

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

Perad

[Resolved] Problem with switch statement

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.