Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <?php
  2.  
  3. function GetLicense($userid, $product)
  4. {
  5. $server = 'localhost';
  6. $username = 'username';
  7. $password = 'password';
  8. $database = 'databaseName';
  9.  
  10.     $con = mysql_connect($server,$username,$password);
  11.     mysql_select_db($database, $con);
  12.  
  13.     /*
  14.     First check to see if the user has a license already
  15.     */
  16.  
  17.     $command = "SELECT license FROM test WHERE userid=$userid and product='$product' limit 1";
  18.     $result = mysql_query($command);
  19.  
  20.     if(mysql_num_rows($result) == 0)
  21.     {
  22.         /*
  23.         Next check if there are any licenses available
  24.         */
  25.         $command2 = "SELECT license FROM test WHERE userid IS NULL AND product='$product' limit 1";
  26.         $result = mysql_query($command2);
  27.         if(mysql_num_rows($result) > 0)
  28.         {
  29.             /*
  30.             set an unassigned code
  31.             */
  32.             $command1 = "UPDATE test SET userid = $userid WHERE license  =(SELECT license FROM (select license from test WHERE userid IS NULL AND product='$product' limit 1) AS temp)";
  33.             $result = mysql_query($command1);
  34.         }
  35.         else
  36.         {
  37.             return "No License's available for this product.";
  38.         }
  39.     }
  40.     /*
  41.     Return code
  42.     */
  43.     $result = mysql_query($command);
  44.     return mysql_result($result,0);
  45.  
  46. }
  47. /*
  48.     below is for sample make sure you sanatize the inputs so users cant fiddle with it
  49. */
  50. echo GetLicense($_GET['u'], 'WS');
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement