Php webservice inserting data to a database

Home / php / Php webservice inserting data to a database

In my Authentication.php class I hava a code like below;
public function prepareTicket($data){
if(array_key_exists(‘tickettype’, $data))
$this->tickettype = $data[‘tickettype’];

if(array_key_exists(‘ticketinfo’, $data))
$this->ticketinfo = $data[‘ticketinfo’];

function createTicket(){
$sql = "INSERT INTO ticket_test (tickettype, ticketinfo) VALUES (‘$this->tickettype’,’$this->ticketinfo’)";
$result = mysqli_query($this->DB_CONNECTION,$sql);


function createTicketControl(){
$sql = "SELECT * FROM `ticket_test` WHERE tickettype = ‘".$this->tickettype."’AND ticketinfo =’".$this->ticketinfo."’";
$result = mysqli_query($this->DB_CONNECTION,$sql);

if(mysqli_num_rows($result) >0){
return true;
return false;
and in the other php file I have a code like this;
$ticketStatus = $auth->createTicketControl();

$json[‘success’] = 1;
$json[‘message’] = ‘Destek kaydı oluşturuldu’;

$json[‘success’] = 0;
$json[‘message’] = ‘Error!’;

echo json_encode($json);
Now my problem is that whenever I try to insert data to my database it returns ‘success’ = ‘0’ , ‘message’ = ‘Error’ and the data couldnt be inserted on the database.I mean the service is not working properly.Any help is appreciated…

P.S.= I am aware of sql injection threat on this code bu it is for android app so no need to worry about it.

Found the solution.I realised that in CreateTicket.php I didint call createTicket function from Authentication.php :/
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *