Jump to content

[Resolved] Problem with switch statement


Perad

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]
Link to comment
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.
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.