I have looked at the same code for hours trying to figure out why my queries are not working. The two I have listed below are the two that are not working.
$getRequestIdQuery = "SELECT request_id FROM request_table WHERE request_key = '$requestKey' AND sort_order = $so"; $getRequestId = $pdo->prepare($getRequestIdQuery); $getRequestId->execute(); foreach($getRequestId as $idRow) { $requestId = $idRow['request_id']; } // This will update the ready status of the request id returned above $updateReadyStatusQuery = "UPDATE request_table SET request_ready = 1 WHERE request_id = $requestId"; $updateReadyStatus = $pdo->prepare($updateReadyStatusQuery); $updateReadyStatus->execute(); The above runs whenever a file copy returns true. I am already sure this is running as there are omitted error logs from the above that show up during every test run. I am also certain the query in question works as I have successfully run the query (as it shows up in the error log) in phpmyadmin. The following is a snippet of code only a few lines above this that runs correctly:
$checkForComposedQuery = "SELECT * FROM composed_files WHERE file_source_id = '$fsi' AND file_number = '$fn'"; $checkForComposed = $pdo->prepare($checkForComposedQuery); $checkForComposed->execute(); Any hints as to what might be causing this to not work? Both of the above snippets occur within a foreach loop if that helps.
Much thanks in advance.
UPDATE:
The following incorporates code that includes suggestions added by Charles below:
$gotCopied = copy($sourceHymnFile, $destHymnFile); if ($gotCopied == true) { error_log("The file has been successfully copied."); $idRow; $getRequestIdQuery = "SELECT request_id FROM request_table WHERE request_key = ? AND sort_order = ?"; $getRequestId = $pdo->prepare($getRequestIdQuery); $getRequestId->execute(array($requestKey, $so)); error_log("this is the value of request key : ".$requestKey); // Displays correct $requestKey value error_log("This is the value of sort order : ".$so); // Displays correct $so value $idRow = $getRequestId->fetch(PDO::FETCH_ASSOC); $requestId = $idRow['request_id']; error_log("This is the value of the request id : ".$requestId); // No output in error log for $requestId above // This will update the ready status of the request id returned above $updateReadyStatusQuery = "UPDATE request_table SET ready = 1 WHERE request_id = ?"; error_log("This updates the status of the song request if the song is played : ".$updateReadyStatusQuery); $updateReadyStatus = $pdo->prepare($updateReadyStatusQuery); $updateReadyStatus->execute(array($requestId)); } The following correctly runs correctly for constants as entered:
if ($gotCopied == true) { error_log("The file has been successfully copied."); $idRow; $getRequestIdQuery = "SELECT request_id FROM request_table WHERE request_key = ? AND sort_order = ?"; $getRequestId = $pdo->prepare($getRequestIdQuery); $getRequestId->execute(array(5, 2)); error_log("this is the value of request key : ".$requestKey); error_log("This is the value of sort order : ".$so); $idRow = $getRequestId->fetch(PDO::FETCH_ASSOC); $requestId = $idRow['request_id']; error_log("This is the value of the request id : ".$requestId); // No output in error log for $requestId above // This will update the ready status of the request id returned above $updateReadyStatusQuery = "UPDATE request_table SET ready = 1 WHERE request_id = ?"; error_log("This updates the status of the song request if the song is played : ".$updateReadyStatusQuery); $updateReadyStatus = $pdo->prepare($updateReadyStatusQuery); // This execute works correctly if a value is set for $requestId $updateReadyStatus->execute(array($requestId)); }
pdo::query(). Use it to solve your issue. In your particular case though I'd better bind$fsiand$fnvariables.$soand$requestKey? 5 and 2? What's the value of$getRequestId-rowCount()after the execute? I'm willing to bet that it's zero.