Jump to content


Photo

[Resolved] Problem with switch statement


  • Please log in to reply
2 replies to this topic

#1 Perad

Perad
  • Members
  • PipPipPip
  • Advanced Member
  • 287 posts

Posted 25 October 2006 - 01:52 PM

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

<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();


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 October 2006 - 01:55 PM

You need to remove the isset() from within the switch() argument. Test it first, eg;

if (isset($_POST['matchsize'])) {
  switch($_POST['matchsize']) {
    // rest of code
  }
}

PS: Whatever editor your using is terrible for cut and paste.

#3 Perad

Perad
  • Members
  • PipPipPip
  • Advanced Member
  • 287 posts

Posted 25 October 2006 - 01:57 PM

Magic, thx mate




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users