I have written a code that uploads values to mysql server , i'm testing from Postman and it does send data and connects successfully but no data is pushed into my database , i appreciate any help ,
- Php code
<?php
include_once('db.php');
// init db
$conn = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
if($conn -> connect_error){
print("Failed to connect to server");
} else {
print("Connected\n");
writeDataToServer();
}
function writeDataToServer(){
global $conn;
$TABLE = 'countryInfo';
if($_SERVER['REQUEST_METHOD'] == "POST"){
$countryName = $_POST['countryName'];
$countryPhone = $_POST['countryPhone'];
$countryCurrency = $_POST['countryCurrency'];
if(!empty(trim($countryName)) && !empty(trim($countryPhone)) && !empty(trim($countryCurrency))){
echo 'Values check passed';
$sql = "INSERT INTO `countryInfo` ('countryName','countryPhone','countryCurrency') VALUES (?,?,?)";
$stmt = $conn -> prepare($sql);
$stmt ->bind_param("sss",$countryName,$countryPhone,$countryCurrency);
$stmt -> execute();
echo 'Successfully Inserted';
$stmt -> close();
$conn -> close();
} else {
echo "Please check if all values are set";
}
} else {
echo 'REQUEST METHOD IS NOT POST';
}
}
?>