TimUSA Posted December 31, 2007 Share Posted December 31, 2007 When this submits to the database, it is not calculating $points correctly??? // CONFIGURATION SECTION $times = $_POST['boats']; $x = 0; ///POST TO DATABASE if (isset($_POST['submitted'])) { if ($_POST['points'][$x] == "DNF") $points = ($_POST['boats'] +1) * $_POST['factor']; else if ($_POST['points'][$x] == "DNS") $points = ($_POST['boats'] +1) * $_POST['factor']; else $points = $_POST['points'][$x] * $_POST['factor']; if ($_POST['factor'] == "3") { while ($x < $times) { mysql_query("INSERT INTO `ladder_points` (`memberName`, `raceDate`, `factor`, `racePoints`, `matchPoints`) VALUES ('{$_POST['name'][$x]}','{$_POST['date']}','{$_POST['factor']}','{$_POST['points'][$x]}','{$points}') "); $x++; } } else { while ($x < $times) { mysql_query("INSERT INTO `ladder_points` (`memberName`, `raceDate`, `factor`, `racePoints`, `fleetPoints`) VALUES ('{$_POST['name'][$x]}','{$_POST['date']}','{$_POST['factor']}','{$_POST['points'][$x]}','{$points}') "); $x++; } } } Quote Link to comment https://forums.phpfreaks.com/topic/83800-solved-not-doin-the-math-right/ Share on other sites More sharing options...
btherl Posted December 31, 2007 Share Posted December 31, 2007 What does it do, and what did you expect it to do? Quote Link to comment https://forums.phpfreaks.com/topic/83800-solved-not-doin-the-math-right/#findComment-426407 Share on other sites More sharing options...
TimUSA Posted December 31, 2007 Author Share Posted December 31, 2007 the first part gets data from a previously submitted form $_POST['boats'] = the number of boats entered into a race $_POST['factor'] = a weighting factor for calculating points for a ladder $_POST['points'] = equals the actual points scored in the race so: if ($_POST['points'][$x] == "DNF") $points = ($_POST['boats'] +1) * $_POST['factor']; else if ($_POST['points'][$x] == "DNS") $points = ($_POST['boats'] +1) * $_POST['factor']; if points scored = DNF (Did Not Finish) or DNS (Did Not Start) (ladder points = (number of boats + 1) * weighting factor) else $points = $_POST['points'][$x] * $_POST['factor']; otherwise (ladder points = actual points * weighting factor) the above parts work because I have echoed the values to test them, what is not working is when I am posting them to the database: if ($_POST['factor'] == "3") { while ($x < $times) { mysql_query("INSERT INTO `ladder_points` (`memberName`, `raceDate`, `factor`, `racePoints`, `matchPoints`) VALUES ('{$_POST['name'][$x]}','{$_POST['date']}','{$_POST['factor']}','{$_POST['points'][$x]}','{$points}') "); $x++; So if the factor is 3 then assign points to the matchPoints column: or else { while ($x < $times) { mysql_query("INSERT INTO `ladder_points` (`memberName`, `raceDate`, `factor`, `racePoints`, `fleetPoints`) VALUES ('{$_POST['name'][$x]}','{$_POST['date']}','{$_POST['factor']}','{$_POST['points'][$x]}','{$points}') "); $x++; basically all other factors, assign to the fleet racing column all seems to be inserting correctly except the above points calculation '{$points}' this is what a sample looks like in the database: raceIDmemberNameDatefactorracePointsmatchPointsfleetPoints 39ARK Racing2007-12-2843.00NULL3.00 so if fleetPoints = racePoints * factor in this example this should be 12 not 3 Quote Link to comment https://forums.phpfreaks.com/topic/83800-solved-not-doin-the-math-right/#findComment-426664 Share on other sites More sharing options...
Ken2k7 Posted January 6, 2008 Share Posted January 6, 2008 if ($_POST['points'][$x] == "DNF") $points = ($_POST['boats'] +1) * $_POST['factor']; else if ($_POST['points'][$x] == "DNS") $points = ($_POST['boats'] +1) * $_POST['factor']; That's redundant. Same as: if ($_POST['points'][$x] == "DNF" || $_POST['points'][$x] == "DNS") $points = ($_POST['boats'] +1) * $_POST['factor']; You don't need {} around $points. Did you try echoing out what $points is before you insert it into the database? Quote Link to comment https://forums.phpfreaks.com/topic/83800-solved-not-doin-the-math-right/#findComment-432068 Share on other sites More sharing options...
btherl Posted January 7, 2008 Share Posted January 7, 2008 the above parts work because I have echoed the values to test them, what is not working is when I am posting them to the database: I think it's likely that they query is not succeeding. Can you do your queries like this: $result = mysql_query("..."); if ($result === false) die("Error in query: " . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/83800-solved-not-doin-the-math-right/#findComment-432239 Share on other sites More sharing options...
mike1313 Posted January 7, 2008 Share Posted January 7, 2008 or $result = mysql_query("...") or die("Error in query: " . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/83800-solved-not-doin-the-math-right/#findComment-432834 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.