Can't manage to insert data into table
This is an example of the file that has to be inserted into my database. the file get's uploaded to the server with a simple form.
{
“FileName”: “XXXX",
“Code”: “11112233",
“Contacts”: [
{
“rowId” => '',
“TicketId” => "xxxxxxxxxxxx",
“otherId” => "YYYYYYYYYYYYYYYYYYYYYYY",
“ClientId” => "wwwwwwwwwwwwwwwwwwwwwwwwwww",
“Name” => "MARCELLO",
“LName” => "MARCELLO",
“Phone” => "4315415151434",
“ADDRESS” => "hhhhhvofvofvvv",
“Mail” => "dfwfwf@fwes.fd"
},
{
“rowId” => '',
“TicketId” => "xxxxxxxxxxxx",
“otherId” => "YYYYYYYYYYYYYYYYYYYYYYY",
“ClientId” => "wwwwwwwwwwwwwwwwwwwwwwwwwww",
“Name” => "MARCELLO",
“LName” => "MARCELLO",
“Phone” => "4315415151434",
“ADDRESS” => "hhhhhvofvofvvv",
“Mail” => "dfwfwf@fwes.fd"
}
]
}
In the main page i include the script for the connection to the database i'm sure that it works, normally used for all other pages of my web work.
$host = "localhost";
$db_user = "xxxx";
$db_pw = "xxxxx";
$db_name = "xxxxx";
// connessione
try {
// stringa di connessione al DBMS
$connessione = new PDO("mysql:host=$host;dbname=$db_name", $db_user, $db_pw);
// impostazione dell'attributo per il report degli errori
$connessione->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
// notifica in caso di errore nel tentativo di connessione
echo "Errore:" .$e->getMessage();
die();
}
This is tha part of the code of my upload page that is not doing the magic for me:
$file = file_get_contents($filejson);
if(!function_exists('json_decode')) die('Il server non ha tale funzione');
$result = json_decode($file, true);
foreach ($result as $row){
$sql = "INSERT INTO ibl_Anag (TicketId,otherId,ClientId,Name,LName,MobPhone,Phone,address,mail)
VALUES ('".$row["TicketId"]."'
,'".$row["otherId"]."'
,'".$row["ClientId"]."'
,'".$row["Name"]."'
,'".$row["LName"]."'
,'".$row["Phone"]."'
,'".$row["MainPhone"]."'
,'".$row["address"]."'
,'".$row["mail"]."' )";
$stmt=$connessione->prepare($sql);
$stmt->execute();
if(!$stmt){Echo "la insert non ha funzionato";}
}
I don't get errors from the code but the data doesn't insert into the mysql table. Probably i'm doing something wrong in the logic of the script but can't understand where. Can any one please help me. thanks.