<?php include('includes/config/config.php'); include('log_entry.php'); $id = $_POST['id']; $name = $_POST['name']; $data = array(); if (!empty($id)) { $query = "select * from habits where habit_id = '$id' "; if (!$result = @mysqli_query($conn, $query)) { die(mysqli_error($conn)); } if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { $data = $row; } } else { $data['status'] = 200; $data['message'] = "Data not found!"; } } else { $query = "select * from habits where upper(habit)= upper('$name') "; error_log($query); if (!$result = @mysqli_query($conn, $query)) { die(mysqli_error($conn)); } if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { array_push($data, $row); } } else { $data['status'] = 200; $data['message'] = "Data not found!"; } $data['count'] = mysqli_num_rows($result); } // error_log(print_r($data, true)); echo json_encode($data);