Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <?php
  2. $id = $_POST["id"];
  3.  
  4. $connection = curl_init();
  5. curl_setopt($connection, CURLOPT_URL, "http://southamptonstudentrooms.com/Wad/downloadwebservice3.php");
  6. $dataToPost = array ("id" => $id);
  7. curl_setopt($connection,CURLOPT_RETURNTRANSFER,1);
  8. curl_setopt($connection,CURLOPT_POSTFIELDS,$dataToPost);
  9. $response = curl_exec($connection);
  10. // display any errors
  11. if(curl_errno($connection)){
  12. echo 'Curl error: ' . curl_error($ch);
  13. }
  14. curl_close($connection);
  15. if ($response == "OK") {
  16. echo "updated";
  17. }
  18. else if ($response == ' ERROR') {
  19. echo "updated failed";
  20. }
  21. else {
  22. echo "error";
  23. }
  24. echo "<br><br>test responce =" . $response;
  25. ?>
  26.  
  27. <?php
  28. $servername = "localhost";
  29. $username = ".........";
  30. $password = ".........";
  31. $dbname = "..........";
  32. $ID = $_POST["id"];
  33.  
  34. // 11: Chris Palmer, username ChrisPalmer, Password tree987, Balance 2.00
  35. // Create connection
  36. $conn = mysqli_connect($servername, $username, $password, $dbname);
  37. // Check connection
  38. if (!$conn) {
  39. die("Connection failed: " . mysqli_connect_error());
  40. }
  41.  
  42. $sql = "SELECT * FROM ht_users WHERE username='ChrisPalmer'";
  43. $result = mysqli_query($conn, $sql);
  44.  
  45. if (mysqli_num_rows($result) > 0) {
  46. // output data of each row
  47. while($row = mysqli_fetch_assoc($result)) {
  48. if($row["balance"] >= 0.79)
  49. {
  50. echo "OK";
  51. mysqli_close($conn);
  52. try {
  53. //WAI
  54. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  55. // set the PDO error mode to exception
  56. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  57.  
  58. $sql = "UPDATE wadsongs SET downloads=downloads + 1 WHERE songid='$ID'";
  59.  
  60. // Prepare statement
  61. $stmt = $conn->prepare($sql);
  62.  
  63. // execute the query
  64. $stmt->execute();
  65.  
  66. // echo a message to say the UPDATE succeeded
  67. // echo $stmt->rowCount() . " records UPDATED successfully";
  68. }
  69. catch(PDOException $e)
  70. {
  71. echo $sql . "<br>" . $e->getMessage();
  72. }
  73. $conn = null;
  74. }
  75. else{
  76. ECHO "ERROR";
  77. }
  78. }
  79. }
  80. else {
  81. echo "0 results";
  82. mysqli_close($conn);
  83. }
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement