Insert to sql and delete duplicate...

  1. <?php
  2.  
  3. /*
  4.         The following variables need to be changed to your webserver details
  5.         Ensure the variables names themselves remain the same though
  6. */
  7.  
  8. $db_name = 'amusich_sr_scores'; // Database name
  9. $username = 'amusich_amusic'; //Your database username
  10. $password = 'jingle330036'; //Your database password (for logging in with above username)
  11. $host = 'localhost'; // hostedAddress - in the form of a link if on a website?
  12. $tbl_name = 'scores'; // Table name in which is being accessed - i,e "gamescoreboard"
  13.  
  14. $dblink = mysql_connect($host,$username,$password);
  15. $seldb = mysql_select_db($db_name);
  16.  
  17.  
  18. if(isset($_POST['name']) && isset($_POST['score']))
  19. {
  20.      // sanitize the GET's to help prevent SQL injection or attacks - possibly not 100% safe, but can help!
  21.      $name = strip_tags(mysql_real_escape_string($_POST['name']));
  22.      $score = strip_tags(mysql_real_escape_string($_POST['score']));
  23.      // provjera da li name+score postoji
  24.      $check=mysql_query("SELECT * FROM `$db_name`.`$tbl_name` WHERE `name`='".$name."' AND `score`=".$score);
  25.          echo "name=".$name;
  26.          echo "score=".$score;
  27.          echo "rezultati=". mysql_num_rows($check);
  28.          if(mysql_num_rows($check) = 0)
  29.      {
  30.       // ne postoji rezultat sa tim $name i $score
  31.                  
  32.           // insert novog
  33.          $sql = mysql_query("INSERT INTO `$db_name`.`$tbl_name` (`name`,`score`) VALUES (\"$name\", $score );");
  34.      }  
  35.      //if($sql)    
  36.      {
  37.         //The query returned true, we're done here!
  38.      echo 'Your score was saved to the database, we are done here!';
  39.      }
  40.          else
  41.          {
  42.           //The query returned false, this isn't good! Log report to text file for further analysis?
  43.           echo 'Your score could not be saved, if this continues please check your database or contact the developer :)';
  44.           echo mysql_errno($dblink) . ": " . mysql_error($dblink). "\n";
  45.      }
  46. }
  47. else
  48. {
  49.      echo 'Your name or score wasnt passed in the request. Make sure the values were passed in from C# correctly.';
  50. }
  51.  
  52. // close the SQL database link, so resources are saved and constant communication between the application and database host doesn't affect use
  53. mysql_close($dblink);
  54.  
  55. ?>

連絡先: info@paste.jp
Created by Paste.jp - v7.0