Guest User

Untitled

a guest
Jan 22nd, 2018
166
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //open connection to mysql db
  3. define('hostname','localhost');
  4. define('username','root');
  5. define('password','');
  6. define('db','test');
  7.  
  8. $connection = mysqli_connect(hostname,username,password,db) or die("Error " . mysqli_error($connection));
  9.  
  10. $search = $_GET['code'];
  11.  
  12. //fetch table rows from mysql db
  13. $sql = "SELECT * FROM barcode WHERE name like '%$search%'";
  14. $result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));
  15.  
  16. //create an array
  17.  
  18. $emparray = array();
  19. $status = "status";
  20. $message = "message";
  21.  
  22. if (mysqli_num_rows($result)>0) {
  23. # code...
  24. $row = mysqli_fetch_row($result);
  25. $name = $row[1];
  26. $poster = $row[2];
  27. $duration = $row[3];
  28. $rating = $row[4];
  29. $released = $row[5];
  30. $genre = $row[6];
  31. $price = $row[7];
  32. $director = $row[8];
  33. $code = "Ticket response:";
  34. array_push($emparray, array("name"=>$name,"poster"=>$poster,"duration"=>$duration,"rating"=>$rating,
  35. "released"=>$released,"genre"=>$genre,"price"=>$price,
  36. "director"=>$director));
  37. }
  38.  
  39. if (!$sql) {
  40. echo json_encode(array(null,$status=>0,$message=>"failed"));
  41. } else {
  42. echo json_encode(array($emparray,$status=>1,$message=>"success"));
  43. }
  44. //close the db connection
  45. mysqli_close($connection);
  46. ?>
RAW Paste Data