Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. <?php
  2.  
  3. require_once "Connection.php";
  4. $dbconnection = new Database('localhost', 'root', '', 'cardimages');
  5.  
  6. $Name = $_POST['cardname'];
  7. $Colour = $_POST['colour'];
  8. $Rarity = $_POST['rarity'];
  9.  
  10. $CardQuery = "INSERT INTO `testimage` (`Name`, `Colour`, `Rarity`) VALUES (:Name, :Colour, :Rarity)";
  11.  
  12. $CardResult = $dbconnection->Connection->prepare($CardQuery);
  13. $CardExec = $CardResult->execute(array(":Name"=>$Name,":Colour"=>$Colour,":Rarity"=>$Rarity));
  14.  
  15. if ($CardExec) {
  16. Echo "The data was inserted!";
  17. } else {
  18. echo "The data wasn't inserted!";
  19. }
  20.  
  21. $query_array = array('name'=>$_POST['cardname'], 'type'=> 'card', '.jpg');
  22. $url = "http://gatherer.wizards.com/Handlers/Image.ashx?".http_build_query($query_array);
  23. $img = "Images/" . ucwords($Name) . ".png";
  24. file_put_contents($img, file_get_contents($url));
  25.  
  26. ?>
  27.  
  28. <?php
  29.  
  30. Class Database {
  31.  
  32. private $hostname;
  33. private $username;
  34. private $password;
  35. private $database;
  36. public $Connection;
  37.  
  38. public function __construct($hostname, $username, $password, $database) {
  39.  
  40. $this->hostname;
  41. $this->username;
  42. $this->password;
  43. $this->database;
  44. $this->Connect();
  45.  
  46. }
  47.  
  48. private function SetHostname($hostname) {
  49.  
  50. $this->hostname = $hostname;
  51.  
  52. return $this;
  53.  
  54. }
  55.  
  56. private function SetUsername($username) {
  57.  
  58. $this->username = $username;
  59.  
  60. return $this;
  61.  
  62. }
  63. private function SetPassword($password) {
  64.  
  65. $this->password = $password;
  66.  
  67. return $this;
  68.  
  69. }
  70. private function SetDatabase($database) {
  71.  
  72. $this->database = $database;
  73.  
  74. return $this;
  75.  
  76. }
  77.  
  78. public function GetHostname() {
  79.  
  80. return $this->hostname;
  81.  
  82. }
  83.  
  84. public function GetUsername() {
  85.  
  86. return $this->username;
  87.  
  88. }
  89.  
  90. public function GetPassword() {
  91.  
  92. return $this->password;
  93.  
  94. }
  95.  
  96. public function GetDatabase() {
  97.  
  98. return $this->database;
  99.  
  100. }
  101.  
  102. private function Connect() {
  103.  
  104. try
  105. {
  106. $db = $this->Connection = new PDO('mysql:host=' . $this->hostname . ';dbname=' . $this->database . '', $this->username, $this->password);
  107.  
  108. echo "This connected successfully!";
  109.  
  110. }
  111. catch (PDOException $e)
  112. {
  113.  
  114. echo "It didn't connect to the database!";
  115.  
  116. }
  117.  
  118. }
  119.  
  120. }
  121.  
  122. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement