I am using the Slim PHP framework for my API. In this function, I have used two statements $sql
and $sql1
to execute two different queries. $sql
is getting inserted successfully whereas $sql1
is not. I am unable to debug this code.
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app->post('/insert/work_experience', function (Request $request, Response $response) {
$user_id = $_POST[0];
$company_name = $_POST[1];
$start_date = $_POST[2];
$end_date = $_POST[3];
$designation = $_POST[4];
$vertical = $_POST[5];
$skillstring = $_POST[6];
$skill = unserialize($skillstring);
$sql = "INSERT INTO work_experience (user_id, company_name, start_date, end_date, designation, vertical)
VALUES (:user_id,:company_name,:start_date,:end_date,:designation,:vertical);";
$sql1 = "INSERT INTO skills (user_id, start_date, end_date, skill)
VALUES (:user_id,:start_date,:end_date,:skill);";
try{
//make db object
$db = new db();
//connection
$db = $db->connect();
$stmt = $db->prepare($sql);
$stmt->bindParam(':user_id', $user_id);
$stmt->bindParam(':company_name', $company_name);
$stmt->bindParam(':start_date', $start_date);
$stmt->bindParam(':end_date', $end_date);
$stmt->bindParam(':designation', $designation);
$stmt->bindParam(':vertical', $vertical);
$stmt->execute(); //This statement is being executed successfully
$stmt1 = $db->prepare($sql1);
$stmt1->bindParam(':user_id', $user_id);
$stmt1->bindParam(':start_date', $start_date);
$stmt1->bindParam(':end_date', $end_date);
$i=0;
while($i<count($skill)){
$skill1 = $skill[$i];
$stmt1->bindParam(':skill', $skill1);
$i++;
$stmt1->execute(); //This statement is not being executed
}
echo '{"notice": {"text": "Data Added"}';
} catch(PDOException $e){
echo '{"error": {"text": '.$e->getMessage().'}';
}
});