Guest User

Untitled

a guest
Oct 23rd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php
  2. header('Access-Control-Allow-Origin: *');
  3. header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
  4. header('Access-Control-Allow-Headers: Content-Type,x-prototype-version,x-requested-with');
  5. header('Cache-Control: max-age=900');
  6. header("Content-Type: application/json"); // tell client that we are sending json data
  7.  
  8. $servername = "localhost";
  9. $username = "saurabh_adminv8";
  10. $password = "adminv8";
  11. $dbname = "saurabh_adminv8";
  12.  
  13. // Create connection
  14. $conn = new mysqli($servername, $username, $password, $dbname);
  15. // Check connection
  16. if ($conn->connect_error) {
  17.     die("Connection failed: " . $conn->connect_error);
  18. }
  19.  
  20.  
  21. $id;
  22. $data = json_decode(file_get_contents('php://input'), true);
  23. if(!empty($data)) {
  24.     $id= $data['id'];
  25.  
  26. }
  27.  
  28. if(!empty($_POST)) {
  29.     $id = $_POST['id'];
  30. }
  31.            
  32. // $sql = "SELECT template_id, template_name as name, template_demolink, template_pic, template_code2 FROM template_types where template_id = " . $id;
  33. $sql = "SELECT firstname, lastname, email, favjob FROM crudtable";
  34. $result = $conn->query($sql);
  35. $results = array();
  36.  
  37. if (($result))
  38. {
  39.  
  40.     $row = $result->fetch_assoc();
  41.     $result->free();
  42.  
  43.     echo('{"status":"SUCCESS", "Records": ' . json_encode($row) . '}');
  44.  
  45. }
  46.  
  47.  
  48. $conn->close();
  49.  
  50.  
  51. ?>
Add Comment
Please, Sign In to add comment