Commit 0aa152dc authored by William Paul Liggett's avatar William Paul Liggett

Admin Page: Made the process to update a scheduled test to be less fragile by...

Admin Page: Made the process to update a scheduled test to be less fragile by confirming the database was updated correctly.
parent cea09657
......@@ -47,7 +47,7 @@ else if($test_condition > 4) {
// `$pdo' is defined as the database connection.
require_once "../../../../../protected_site_configs/junktext.com/openvigilance_db_connection.php";
// Test Control: Edit a test in the database.
// Test Control: Submit the edit request to the database.
$sql = "UPDATE test_control SET subject_id=:subject_id, test_condition=:test_condition WHERE sk=:sk";
$statement = $pdo->prepare($sql);
$statement->bindValue(":subject_id", $subject_id, PDO::PARAM_INT);
......@@ -55,5 +55,23 @@ $statement->bindValue(":test_condition", $test_condition, PDO::PARAM_INT);
$statement->bindValue(":sk", $sk, PDO::PARAM_INT);
$statement->execute();
// Inform the web browser that all went well.
output_json_response(true, "");
// Verify the database has updated the test record.
$sql = "SELECT subject_id, test_condition FROM test_control WHERE sk=:sk";
$statement = $pdo->prepare($sql);
$statement->bindValue(":sk", $sk, PDO::PARAM_INT);
$statement->execute();
$modified_record = $statement->fetch();
// `$modified_record' should now be an array of one row with two named indexes: ['subject_id'] and ['test_condition']
// Initially, the all cell contents of the `$modified_record' are strings when grabbing data from MySQL. This is why intval() is used.
// This behavior can be overridden to grab the native MySQL database types, but it's not that essential right now.
// See: https://stackoverflow.com/questions/34397994/pdo-fetch-data-returns-array-of-string
if((intval($modified_record['subject_id']) === $subject_id) && (intval($modified_record['test_condition']) === $test_condition)) {
// Inform the web browser that all went well.
output_json_response(true, "");
}
else {
// The database was not properly updated for some reason.
output_json_response(false, "The input data was valid, but the database could not be updated at this time for some reason.");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment