I am a beginner and I need to create an API for my website, that will be used to post data into my SQL Server database.
I found a tutorial on Youtube but it doesnt seem to work for me.
(I am getting a blank page with just this in it: [])
Any help will be appreciated.
This is the code I have at the moment:
<?php
include("connection.php");
$response=array();
if($conn){
$sql="select * from [new_candidate]";
$result = sqlsrv_query( $conn, $sql, array(), array( "Scrollable" => 'static' ));
if($result) {
header("Content-Type:JSON");
$i=0;
while($row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC)){
$response[$i]["candidate_id"] = $row["candidate_id"];
$response[$i]["first_name"] = $row["first_name"];
$response[$i]["last_name"] = $row["last_name"];
$response[$i]["email"] = $row["email"];
$response[$i]["tel"] = $row["tel"];
$response[$i]["branch"] = $row["branch"];
$response[$i]["job_id"] = $row["job_id"];
$response[$i]["job_title"] = $row["job_title"];
$response[$i]["date_applied"] = $row["date_applied"];
$i++;
}
echo json_encode($response, JSON_PRETTY_PRINT);
}
} else {
include_once("no_connection.php");
}