tooNight Posted March 31, 2006 Share Posted March 31, 2006 Hi there struggling with IF statements, I have a form where players can insert their results against another players. The players submit their results e.g. 3-0, 3-1, 3-2, 0-3, 1-3, 2-3, . The if statement is below is very sketchy php & pseudo code, just wondering if anybody could correct my if statement or tell me a better way to do it. I have a table called indResults and when a player submits a result I want to put the words "WIN" or "LOSS" in the table recording the results. depending on which player got to 3 games first and won.At the moment the form submits but does not submit values for $pWL1, $pWL2 which I have tried to work out in the IF statement.Please could somebody help me please as I am tearing my hair out here, would be great if you could!Many ThanksLeonP.S. [a href=\"http://www.squashcommunities.com/inputresults.php\" target=\"_blank\"]Here is the webpage to get an idea of the scores[/a][code]<?phprequire 'library/db_connect.php'; // database connect script.?><?phpif (isset($_POST['submit'])) { // if form has been submitted /* check they filled in what they supposed to, passwords matched, username isn't already taken, etc. *///Big IF statement is below which I am having trouble with. $win = "WIN"; $loss = "LOSS"; if(!$_POST['player1Score']== "3" && !$_POST['player2Score'] == "0") { $pWL1 = $win; $pWL2 = $loss; } elseif(!$_POST['player1Score'] == "3" && $_POST['player2Score'] == "1") { $pWL1 == $win; $pWL2 == $loss; } elseif(!$_POST['player1Score'] == "3" && $_POST['player2Score'] == "2") { $pWL1 == $win; $pWL2 == $loss; } elseif(!$_POST['player1Score'] == "0" && $_POST['player2Score'] == "3") { $pWL1 == $loss; $pWL2 == $win; } elseif(!$_POST['player1Score'] == "1" && $_POST['player2Score'] == "3") { $pWL1 == $loss; $pWL2 == $win; } elseif(!$_POST['player1Score'] == "2" && $_POST['player2Score'] == "3") { $pWL1 == $loss; $pWL2 == $win; } elseif(!$_POST['player1Score'] == "2" && $_POST['player2Score'] == "2") { die ('Only Completed Matches Count'); } elseif(!$_POST['player1Score'] == "1" && $_POST['player2Score'] == "1") { die ('Only Completed Matches Count'); } elseif(!$_POST['player1Score'] == "0" && $_POST['player2Score'] == "0") { die ('Only Completed Matches Count'); } include 'library/header.inc';$insertScore = "INSERT INTO indMatch ( indMatchID, player1ID, player2ID, player1Sco, player2Sco, p1WinLoss, p2WinLoss) VALUES ( NULL, '".$_POST['pID']."', '".$_POST['player2']."', '".$_POST['player1Score']."', '".$_POST['player2Score']."', $pWL1, $pWL2)";$add_result = $db_object->query($insertScore);include 'library/footer.inc'?><?php } else { // if form hasn't been submitted?><?php include 'library/header.inc'; ?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <?php$findName = "SELECT playerID, playerName, email FROM players WHERE (email = '".$_SESSION['emailusername']."')";$findPlayer = mysql_query($findName) or die(mysql_error());while($row=mysql_fetch_assoc($findPlayer)) {echo "$row[playerName]";echo "<input type=hidden name=pID value=$row[playerID]>";}?><select name=player1Score><option value=3>3</option><option value=2>2</option><option value=1>1</option><option value=0>0</option></select><?php$p2=mysql_query("SELECT players.playerID, players.playerName FROM players") or die(mysql_error());echo "<select name=player2>";while($row=mysql_fetch_assoc($p2)) {echo "<option value=$row[playerID]>$row[playerName]</option>";}echo "</select>";?><select name="player2Score"><option value="3">3</option><option value="2">2</option><option value="1">1</option><option value="0">0</option></select><input type="submit" name="submit" value="Confirm Result"></form><?php include 'library/footer.inc'; ?><?php$db_object->disconnect();?><?php}?> [/code] Quote Link to comment Share on other sites More sharing options...
alpine Posted March 31, 2006 Share Posted March 31, 2006 could something like this do for your needs ?[code]<?if($_POST['player1Score'] == $_POST['player2Score']){die ('Only Completed Matches Count');}else{if($_POST['player1Score'] > $_POST['player2Score']){$pWL1 = $win;$pWL2 = $loss;}if($_POST['player1Score'] < $_POST['player2Score']){$pWL1 == $loss;$pWL2 == $win;}}?>[/code] Quote Link to comment Share on other sites More sharing options...
tooNight Posted March 31, 2006 Author Share Posted March 31, 2006 Yep that works a treat, thank you very much :D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.