Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. [23-Sep-2017 20:04:17 UTC] PHP Notice: Undefined variable: results in /home/harabla/public_html/testi/update.php on line 46
  2.  
  3. <?php
  4. $servername = "myserver";
  5. $username = "user";
  6. $password = "pass";
  7. $dbname = "dbname";
  8.  
  9.  
  10. // Create connection
  11. $conn = new mysqli($servername, $username, $password, $dbname);
  12. // Check connection
  13. if ($conn->connect_error) {
  14. die("Connection failed: " . $conn->connect_error);
  15. }
  16.  
  17.  
  18. $sql = mysqli_query($conn, "SELECT id from users");
  19. $userinfo = array();
  20.  
  21. while ($row_user = $sql->fetch_assoc())
  22. $userinfo[] = $row_user;
  23.  
  24. foreach ($userinfo as $user) {
  25.  
  26. $url = "http://www.pdga.com/player/".$user['id'];
  27. $ch = curl_init();
  28. $timeout = 5;
  29. curl_setopt($ch, CURLOPT_URL, $url);
  30. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  31. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  32. $html = curl_exec($ch);
  33. curl_close($ch);
  34.  
  35.  
  36. $dom = new DOMDocument();
  37. @$dom->loadHTML($html);
  38.  
  39. $xpath = new DomXPath($dom);
  40. $class = 'current-rating';
  41. $divs = $xpath->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $class ')]");
  42.  
  43. foreach($divs as $div) {
  44. preg_match('/Current Rating:s+(d+)/', $div->nodeValue, $results);
  45. }
  46.  
  47.  
  48. if (!is_null($results[1])){
  49. $sql = "UPDATE users SET rating=$results[1] WHERE id =".$user['id'];
  50. } else {
  51. $sql = "UPDATE users SET rating='0' WHERE id =".$user['id'];
  52. }
  53.  
  54. if ($conn->query($sql) === TRUE) {
  55. echo "Record updated successfully <br>";
  56. } else {
  57. echo "Error updating record <br> " . $conn->error;
  58. }
  59.  
  60. unset($results);
  61.  
  62. }
  63.  
  64. $conn->close();
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement