Advertisement
th3w1zard1

posttoreceivemysql.php

Jul 25th, 2012 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.37 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5.  
  6.  
  7. if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
  8.  
  9.  
  10. {
  11.  
  12.  
  13.     // Displays a multi-dimensional array as a HTML unordered lists.
  14.     function displayTree($array)
  15.     {
  16.         $newline = "";
  17.         foreach($array as $key => $value)    //cycle through each item in the array as key => value pairs
  18.         {
  19.             if (is_array($value) || is_object($value)) //if the VALUE is an array, then
  20.             {        
  21.                 //call it out as such, surround with brackets, and recursively call displayTree.
  22.                 $value = "Array()" . $newline . "(" . displayTree($value) . ")" . $newline;
  23.             }
  24.             //if value isn't an array, it must be a string. output its' key and value.
  25.             $output .= "[\"$key\"] = " . $value . ",\n" . $newline;
  26.         }
  27.         return $output;
  28.     }
  29.  
  30.  
  31.     $con = mysql_connect("extraproclancom.ipagemysql.com","halostatius","!Gameboy01");
  32.  
  33.  
  34.  
  35.     if (!$con)
  36.  
  37.    
  38.     {
  39.  
  40.         die('Could not connect. Error message: ' . mysql_error());
  41.  
  42.     }
  43.  
  44.  
  45.  
  46.     $db_selected = mysql_select_db("halostats", $con);
  47.  
  48.  
  49.  
  50.  
  51.     if (!$db_selected)
  52.  
  53.  
  54.     {
  55.  
  56.  
  57.         die ("Can\'t use database halostats: " . mysql_error());
  58.  
  59.  
  60.     }
  61.    
  62.     //create columns if they don't exist
  63.     foreach ($_POST as $k => $v)
  64.     {
  65.         $query = "SELECT " . $k . " FROM stats";
  66.         $query = mysql_query($query);
  67.         if(!$query)
  68.         {
  69.             $query = "ALTER TABLE `stats` ADD `" . $k . "` " . "TEXT";
  70.             mysql_query($query);
  71.         }
  72.     }
  73.     $hash = $_POST['Hash'];
  74.     echo "SELECT * FROM stats WHERE Hash='$hash';";
  75.     $result = mysql_query("SELECT * FROM stats WHERE Hash='$hash';");
  76.     if(mysql_num_rows($result) == 0)
  77.     {
  78.        
  79.         $keys = "INSERT INTO `stats` (";
  80.         $values = "VALUES (";
  81.         $bool = true;
  82.         foreach ($_POST as $k => $v)
  83.         {
  84.             if($bool)
  85.             {
  86.                 $keys = $keys . "`" . $k . "`";
  87.                 $values = $values . "'" . $v . "'";
  88.                 $bool = false;
  89.             }
  90.             else
  91.             {
  92.                 $keys = $keys . ", `" . $k . "`";
  93.                 $values = $values . ", '" . $v . "'";
  94.             }
  95.         }
  96.         $keys = $keys . ") ";
  97.         $values = $values . ")";
  98.         mysql_query($keys . $values);
  99.        
  100.         //mysql_query("INSERT INTO `stats` (`ip`, `name`, `kills`, `assists`, `deaths`) VALUES ('" . $_POST['ip'] . "', '" . $_POST['name'] . "', '" . $_POST['kills']");");
  101.     }
  102.     else
  103.     {
  104.         foreach ($_POST as $k => $v)
  105.         {
  106.             $query = "UPDATE `stats` set `" . $k . "` = ";
  107.             $query = $query . "'" . $v . "'";
  108.             $query = $query . " WHERE `Hash` = '" . $_POST['Hash'] . "'";
  109.             mysql_query($query);
  110.         }
  111.     }
  112.     mysql_close($con);
  113.  
  114.  
  115. }
  116.  
  117.  
  118. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement