-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
55 lines (45 loc) · 1.61 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
//open connection to mysql db
define('hostname','127.0.0.1');
define('username','root');
define('password','');
define('db','test');
//header('Content-Type: application/json');
$connection = mysqli_connect(hostname,username,password,db) or die("Error " . mysqli_error($connection));
$search = $_GET['code'];
//fetch table rows from mysql db
$sql = "SELECT * FROM barcode WHERE barcodename like '%$search%'";
$result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));
//create an array
$emparray = array();
$status = "status";
$message = "message";
if (mysqli_num_rows($result)>0) {
# code...
$row = mysqli_fetch_row($result);
$name = $row[2];
$poster = $row[3];
$duration = $row[4];
$rating = $row[5];
$released = $row[6];
$genre = $row[7];
$price = $row[8];
$director = $row[9];
$code = "Ticket response:";
array_push($emparray,
array("name"=>$name,"poster"=>$poster,"duration"=>$duration,"rating"=>$rating,
"released"=>$released,"genre"=>$genre,"price"=>$price,
"director"=>$director));
}
$json = ["name"=>$name,"poster"=>$poster,"duration"=>$duration,"rating"=>$rating,
"released"=>$released,"genre"=>$genre,"price"=>$price,
"director"=>$director];
if (!$sql) {
echo json_encode(array(null,$status=>0,$message=>"failed"));
} else {
// echo json_encode(array($emparray,$status=>1,$message=>"success"));
echo json_encode($json);
}
//close the db connection
mysqli_close($connection);
?>