Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // these are the drop down choices from the admin
- // I used POST here, change to GET if thats what your form uses
- if (isset($_POST['racerName'])) {
- $racerName = $_POST['racerName'];
- if (isset($_POST['positionOne'])) {
- $positionOne = $_POST['positionOne'];
- if (isset($_POST['positionTwo'])) {
- $positionTwo = $_POST['positionTwo'];
- // function to get points from position
- function position_to_points($position)
- {
- // if admin chose position 1, then give the full 25 points
- if($position == 1){
- return 25;
- }
- // else, if its not position 1, then subtract the appropriate amount of
- // points from the full amount(25) - (using the position number as the
- // number to subtract by was intuitive by vettels
- else{
- return 25 - $position;
- }
- }
- // using the position_to_points function, add the 2 scores and
- // store the result to $totalScore
- $totalScore = position_to_points($positionOne) + position_to_points($positionTwo) ;
- // now insert that total score into the database for that user
- // if your column names were "username" and "score".....
- // setup the insert statement
- $sql = "INSERT INTO myTable (username, score) values ('".$racerName."', '".$totalScore."')";
- //connect to database
- $servername = "myServer";
- $username = "myUserName";
- $password = "myPassword";
- $db = mysql_connect($servername,$username,$password) or die("Unable to connect to server");
- @mysql_select_db($database) or die("Unable to select database");
- // run the query
- $result = mysql_query($sql);
- ?>
Add Comment
Please, Sign In to add comment