I have an API to do an action for a site.
/api/api.php?api=server&ver=1.0&key=**&cmd=ADD_OBJECT,862011228001930
The API works and does what it needs to be done. The API information is populated from a form I have. the form also needs to upload information to MYSQL database using SQL
I have the following SQL
$sql = "INSERT INTO tracking_units SET status = 'Tech', unit_nr = '".$unit_nr."', imei = '".$imei."', sysdate = '".$date."', systime = '".$time."', controller = '".$slname."', branch = 'JHB', client = 'eTrack'"; if ($conn->query($sql) === TRUE) {$last_id = mysqli_insert_id($conn); //Retrieve the last ID of the record } else { echo "Error: " . $sql . "<br>" . $conn->error; } header("Location: http://***/api/api.php?api=server&ver=1.0&key=***&cmd=ADD_OBJECT,$imei");
The above works as the header runs the API, but once the API is completed I would like to redirect the page to another html page. Is this possible with me running the header command.
I am very new to API’s and not sure how else I can run the API after the SQL command and then use the header to divert to another page
Advertisement
Answer
I have found this to work
$ch = curl_init("http://***/api/api.php?api=server&ver=1.0&key=***&cmd=ADD_OBJECT,$imei,$unit_nr,false,2021-01-01"); curl_exec($ch); if (curl_error($ch)) { fwrite($ch, curl_error($ch)); } curl_close($ch); fclose($ch);