Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5. date_default_timezone_set('Europe/Bucharest');
  6.  
  7. //Database Setting
  8. $servername = "localhost";
  9. $username = "root";
  10. $password = "Tfsg3737ghshgaysh37Hshgdy35ePP";
  11. $dbname = "ebaytoolbar";
  12.  
  13. //Get URL Parameter
  14. $api_key = $_GET['api_key'];
  15.  
  16.  
  17. //decode the parameter $api_key from base 64 to clear (for recreate the email dynamically and insert it into email column)
  18. $str = '$api_key';
  19. $decoded = base64_decode( urldecode( $api_key ) );
  20.  
  21.  
  22. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  23. // set the PDO error mode to exception
  24. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  25. $query = "SELECT `api_key` FROM `users_toolbar` WHERE `api_key` = ?";
  26.  
  27. //Put the parameters in an array
  28. $params = array($str);
  29.  
  30. //Execute it
  31. try {
  32. $stmt = $conn->prepare($query);
  33. # We should prepare request before execute
  34. $stmt->bindParam( 1, $api_key, PDO::PARAM_STR );
  35. $result = $stmt->execute();
  36. } catch(PDOException $ex) {
  37. echo $ex->getMessage();
  38. }
  39.  
  40. //Now Check for the row count
  41. if($stmt->rowCount >= 1) {
  42. echo "API Key Exists NO NEED TO ENTER IT INTO DB AGAIN";
  43. }
  44. //mean the account is not created so we can create it
  45. else
  46.  
  47. {
  48.  
  49.  
  50.  
  51. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  52. // set the PDO error mode to exception
  53. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  54. $sql = "INSERT INTO `users_toolbar` (`email`,`api_key`,`earning`,`reward`,`group`,`installation_date`)
  55. VALUES (?,?,'350','35','basic',NOW())";
  56. // use exec() because no results are returned
  57. try{
  58. # the same thing: bind before execute
  59. $stmt->bindParam( 1, $decoded, PDO::PARAM_STR );
  60. $stmt->bindParam( 2, $api_key, PDO::PARAM_STR );
  61. $stmt->execute;
  62. echo "New record created successfully";
  63. }
  64.  
  65. catch(PDOException $e)
  66. {
  67. echo $sql . "<br>" . $e->getMessage();
  68. }
  69. }
  70.  
  71. $conn = null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement