I have the following PHP
code:
<?php
header("Access-Control-Allow-Origin: *");
include_once('../includes/mysql_connect.php');
include_once('../db/tables/search.php');
// SAVE TO DB
$search = new search($mysql);
//$search->drop();
//$search->create();
$search->save(array("shop" => "test store", "searchterm" => $_POST['search']));
// LOG TO FILE
$file = fopen('search-data.txt', 'a+');
$result = fwrite($file, "\nsearch query data: " . print_r($_POST['search'], true) );
// SEND RESPONSE
$response = array('response' => 'received', 'data' => $_POST['search'] );
echo json_encode($response);
When I look on the browser console I see this:
<br>INSERT QUERY SUCCESSFUL: insert_id=69{"response":"received","data":"product"}
The "INSERT QUERY SUCCESSFUL" is coming from my DB class which does the INSERT and echos out various messages. How can I show only the JSON response in the last two lines of code and not these echoed out messages? I want to keep these messages in my DB class for the moment. I wouldn't have expected anything else other than the data in the response array to be displayed in the console.
ob_end_clean()
, which will just erase everything echo produced up until the command execution. That said, there're specific instruments for logging that should be used for this purposeob_end_clean
.