Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- date_default_timezone_set('Europe/Bucharest');
- //Database Setting
- $servername = "localhost";
- $username = "root";
- $password = "Tfsg3737ghshgaysh37Hshgdy35ePP";
- $dbname = "ebaytoolbar";
- //Get URL Parameter
- $api_key = $_GET['api_key'];
- //decode the parameter $api_key from base 64 to clear (for recreate the email dynamically and insert it into email column)
- $str = '$api_key';
- $decoded = base64_decode( urldecode( $api_key ) );
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $query = "SELECT `api_key` FROM `users_toolbar` WHERE `api_key` = ?";
- //Put the parameters in an array
- $params = array($str);
- //Execute it
- try {
- $stmt = $conn->prepare($query);
- # We should prepare request before execute
- $stmt->bindParam( 1, $api_key, PDO::PARAM_STR );
- $result = $stmt->execute();
- } catch(PDOException $ex) {
- echo $ex->getMessage();
- }
- //Now Check for the row count
- if($stmt->rowCount >= 1) {
- echo "API Key Exists NO NEED TO ENTER IT INTO DB AGAIN";
- }
- //mean the account is not created so we can create it
- else
- {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "INSERT INTO `users_toolbar` (`email`,`api_key`,`earning`,`reward`,`group`,`installation_date`)
- VALUES (?,?,'350','35','basic',NOW())";
- // use exec() because no results are returned
- try{
- # the same thing: bind before execute
- $stmt->bindParam( 1, $decoded, PDO::PARAM_STR );
- $stmt->bindParam( 2, $api_key, PDO::PARAM_STR );
- $stmt->execute;
- echo "New record created successfully";
- }
- catch(PDOException $e)
- {
- echo $sql . "<br>" . $e->getMessage();
- }
- }
- $conn = null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement