Guest User

Untitled

a guest
Dec 4th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. <?php
  2. // these are the drop down choices from the admin
  3.  
  4. // I used POST here, change to GET if thats what your form uses
  5. if (isset($_POST['racerName'])) {
  6. $racerName = $_POST['racerName'];
  7.  
  8. if (isset($_POST['positionOne'])) {
  9. $positionOne = $_POST['positionOne'];
  10.  
  11. if (isset($_POST['positionTwo'])) {
  12. $positionTwo = $_POST['positionTwo'];
  13.  
  14. // function to get points from position
  15. function position_to_points($position)
  16. {
  17. // if admin chose position 1, then give the full 25 points
  18. if($position == 1){
  19. return 25;
  20. }
  21. // else, if its not position 1, then subtract the appropriate amount of
  22. // points from the full amount(25) - (using the position number as the
  23. // number to subtract by was intuitive by vettels
  24.  
  25. else{
  26. return 25 - $position;
  27. }
  28. }
  29.  
  30. // using the position_to_points function, add the 2 scores and
  31. // store the result to $totalScore
  32.  
  33. $totalScore = position_to_points($positionOne) + position_to_points($positionTwo) ;
  34.  
  35. // now insert that total score into the database for that user
  36. // if your column names were "username" and "score".....
  37.  
  38. // setup the insert statement
  39.  
  40. $sql = "INSERT INTO myTable (username, score) values ('".$racerName."', '".$totalScore."')";
  41.  
  42. //connect to database
  43. $servername = "myServer";
  44. $username = "myUserName";
  45. $password = "myPassword";
  46.  
  47. $db = mysql_connect($servername,$username,$password) or die("Unable to connect to server");
  48. @mysql_select_db($database) or die("Unable to select database");
  49.  
  50. // run the query
  51. $result = mysql_query($sql);
  52. ?>
Add Comment
Please, Sign In to add comment