Guest User

Untitled

a guest
Dec 23rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', '1');
  4. // DB info
  5. $dbhost = '10.100.7.5';
  6. $dbuser = 'badams';
  7. $dbpass = 'pizza';
  8. $dbname = 'badams';
  9. $rows = array();
  10. $rows["data"]="";
  11.  
  12. if(isset($_REQUEST['query'])) {
  13. $q = $_REQUEST['query'];
  14. if(strlen($q) > 0) {
  15. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
  16. if(!$conn) {
  17. $rows["success"] = false;
  18. $rows["error"] = "Unable to connect to DB";
  19. echo json_encode($rows);
  20. exit;
  21. }
  22.  
  23. if(!mysql_select_db($dbname)) {
  24. $rows["success"] = false;
  25. $rows["error"] ="Unable to select database.";
  26. echo json_encode($rows);
  27. exit;
  28. }
  29.  
  30. $dbQuery = "SELECT * FROM quicklinks_answers WHERE question_text LIKE '%$q%' LIMIT 15";
  31.  
  32. $result = mysql_query($dbQuery);
  33.  
  34. if(!$result) {
  35. $rows["success"] = false;
  36. $rows["error"] = "Could not successfully run query ($dbQuery) from DB.";
  37. echo json_encode($rows);
  38. exit;
  39. }
  40.  
  41. if(mysql_num_rows($result) == 0) {
  42. $rows["sucess"] = true;
  43. $rows['error'] = "Sorry, no results found";
  44. echo json_encode($rows);
  45. exit;
  46. }
  47.  
  48. while($row = mysql_fetch_assoc($result)) {
  49. $rows["data"][] = $row;
  50. exit;
  51. }
  52. $rows['success'] = "true";
  53. $rows['error'] = "";
  54. echo json_encode($rows);
  55. exit;
  56. }
  57. $rows["success"] = true;
  58. $rows['error'] = "No search was passed";
  59. echo json_encode($rows);
  60. } // don't do anything because there was so search sent
  61.  
  62. ?>
Add Comment
Please, Sign In to add comment