My PHP Code:
<?php
$host = ""; $db_name = ""; $username = ""; $password = "";
try {
$conn = new PDO("mysql:host=".$host.";dbname=".$db_name, $username, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$json = file_get_contents('');
$obj = json_decode($json, TRUE);
$stmt = $conn->prepare("INSERT INTO item_details (item_id,value,circulation) VALUES (:item_id,:value,:circulation");
foreach($obj['items'] as $key => $index) {
$item_id = $key;
$value = $index['value'];
$circulation = $index['circulation'];
$stmt->bindparam(":item_id", $item_id);
$stmt->bindparam(":value", $value);
$stmt->bindparam(":circulation", $circulation);
$stmt->execute();
}
?>
Problem:
I've tested via echoing the data to the page within my loop and the data is being retrieved, however no information is being submitted to my database.
Questions:
- How can I improve upon my script to add relevant debugging lines to find the cause?
- Is it obvious why my script does not work? If so, could you please explain this however my above question will aid my learning curve with future development!