Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function GetLicense($userid, $product)
- {
- $server = 'localhost';
- $username = 'username';
- $password = 'password';
- $database = 'databaseName';
- $con = mysql_connect($server,$username,$password);
- mysql_select_db($database, $con);
- /*
- First check to see if the user has a license already
- */
- $command = "SELECT license FROM test WHERE userid=$userid and product='$product' limit 1";
- $result = mysql_query($command);
- if(mysql_num_rows($result) == 0)
- {
- /*
- Next check if there are any licenses available
- */
- $command2 = "SELECT license FROM test WHERE userid IS NULL AND product='$product' limit 1";
- $result = mysql_query($command2);
- if(mysql_num_rows($result) > 0)
- {
- /*
- set an unassigned code
- */
- $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)";
- $result = mysql_query($command1);
- }
- else
- {
- return "No License's available for this product.";
- }
- }
- /*
- Return code
- */
- $result = mysql_query($command);
- return mysql_result($result,0);
- }
- /*
- below is for sample make sure you sanatize the inputs so users cant fiddle with it
- */
- echo GetLicense($_GET['u'], 'WS');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement