EarthDay Posted October 11, 2023 Share Posted October 11, 2023 Hi there, I am trying to get an update form to work and it does not save the information to the database. My link to update a record is forms/decs-update.php?id=<?=$contact['id']?>&decs_id=<?=$decs['id']?> The information loads on the page from the diabase but does not save the information to the database and give me an error message; No rows updated. Possible reasons: No changes detected or invalid ID. <?php include '../../main.php'; check_loggedin($pdo); $msg = ''; ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); if (!isset($_GET['id'])) { exit('No ID parameter provided!'); } $stmt = $pdo->prepare('SELECT username,email,role FROM accounts WHERE id = ?'); $stmt->execute([ $_SESSION['id'] ]); $account = $stmt->fetch(PDO::FETCH_ASSOC); $stmt = $pdo->prepare('SELECT id,username FROM accounts'); $stmt->execute(); $all_account_info = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt = $pdo->prepare('SELECT * FROM contacts WHERE id = ?'); $stmt->execute([$_GET['id']]); $contact = $stmt->fetch(PDO::FETCH_ASSOC); $Rstmt = $pdo->prepare('SELECT * FROM esf_decs WHERE id = ?'); $Rstmt->execute([$_GET['decs_id']]); $decs = $Rstmt->fetch(PDO::FETCH_ASSOC); if (!$contact) { exit('Contact doesn\'t exist with that ID!'); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { $client_id = trim($_POST["client_id"]); $learning_opportunities = trim($_POST["learning_opportunities"]); $learning_opportunities = trim($_POST["learning_opportunities"]); $contact_for_other_purposes = trim($_POST["contact_for_other_purposes"]); $empowering_communities = trim($_POST["empowering_communities"]); $empowering_communities_name = trim($_POST["empowering_communities_name"]); $empowering_communities_sign = trim($_POST["empowering_communities_sign"]); $empowering_communities_date = trim($_POST["empowering_communities_date"]); $participant_enrolled_onto = trim($_POST["participant_enrolled_onto"]); $participant_moved_another_provider = trim($_POST["participant_moved_another_provider"]); $participant_eligible_free_school = trim($_POST["participant_eligible_free_school"]); $british_passport = trim($_POST["british_passport"]); $eec_passport = trim($_POST["eec_passport"]); $euss_via_home = trim($_POST["euss_via_home"]); $preferred_evidence = trim($_POST["preferred_evidence"]); $provide_preferred_evidence = trim($_POST["provide_preferred_evidence"]); $option_adoption_vertificate = trim($_POST["option_adoption_vertificate"]); $option_driving_licence = trim($_POST["option_driving_licence"]); $option_non_eu_passport = trim($_POST["option_non_eu_passport"]); $option_biometric_immigration = trim($_POST["option_biometric_immigration"]); $option_current_immigration = trim($_POST["option_current_immigration"]); $option_marriage_civil_partnership = trim($_POST["option_marriage_civil_partnership"]); $option_other_evidence = trim($_POST["option_other_evidence"]); $option_nine = trim($_POST["option_nine"]); $details_evidence_provided = trim($_POST["details_evidence_provided"]); $dwp_job_centre_letter = trim($_POST["dwp_job_centre_letter"]); $confirmation_relevant_organisation = trim($_POST["confirmation_relevant_organisation"]); $self_certification_evidence = trim($_POST["self_certification_evidence"]); $partcipant_told_support = trim($_POST["partcipant_told_support"]); $participant_file_completed_remotly = trim($_POST["participant_file_completed_remotly"]); $declaration_name_please_print = trim($_POST["declaration_name_please_print"]); $declaration_job_title = trim($_POST["declaration_job_title"]); $declaration_organisation = trim($_POST["declaration_organisation"]); $declaration_signature_date = trim($_POST["declaration_signature_date"]); $declaration_signature = trim($_POST["declaration_signature"]); $stmt = $pdo->prepare('UPDATE esf_decs SET client_id=?,learning_opportunities=?,contact_for_other_purposes=?,empowering_communities=?,empowering_communities_name=?,empowering_communities_sign=?,empowering_communities_date=?,participant_enrolled_onto=?,participant_moved_another_provider=?,participant_eligible_free_school=?,british_passport=?,eec_passport=?,euss_via_home=?,preferred_evidence=?,provide_preferred_evidence=?,option_adoption_vertificate=?,option_driving_licence=?,option_non_eu_passport=?,option_biometric_immigration=?,option_current_immigration=?,option_marriage_civil_partnership=?,option_other_evidence=?,option_nine=?,details_evidence_provided=?,dwp_job_centre_letter=?,confirmation_relevant_organisation=?,self_certification_evidence=?,partcipant_told_support=?,participant_file_completed_remotly=?,declaration_name_please_print=?,declaration_job_title=?,declaration_organisation=?,declaration_signature_date=?,declaration_signature=? WHERE id=?'); $stmt->execute([$client_id,$learning_opportunities,$contact_for_other_purposes,$empowering_communities,$empowering_communities_name,$empowering_communities_sign,$empowering_communities_date,$participant_enrolled_onto,$participant_moved_another_provider,$participant_eligible_free_school,$british_passport,$eec_passport,$euss_via_home,$preferred_evidence,$provide_preferred_evidence,$option_adoption_vertificate,$option_driving_licence,$option_non_eu_passport,$option_biometric_immigration,$option_current_immigration,$option_marriage_civil_partnership,$option_other_evidence,$option_nine,$details_evidence_provided,$dwp_job_centre_letter,$confirmation_relevant_organisation,$self_certification_evidence,$partcipant_told_support,$participant_file_completed_remotly,$declaration_name_please_print,$declaration_job_title,$declaration_organisation,$declaration_signature_date,$declaration_signature,$_GET['id']]); if($stmt->rowCount()) { $_SESSION['status'] = "The asset information has been successfully updated."; header('Location: ../display.php?id=' . $_GET['id']); exit; } else { $msg = "No rows updated. Possible reasons: No changes detected or invalid ID."; } } catch (PDOException $e) { $msg = "Error: " . $e->getMessage(); } } ?> <form action="decs-update.php?id=<?=$decs['id']?>" method="post" enctype="multipart/form-data"> Database structure `id` int(11) NOT NULL, `client_id` int(11) DEFAULT NULL, `learning_opportunities` varchar(225) DEFAULT NULL, `contact_for_other_purposes` varchar(100) DEFAULT NULL, `empowering_communities` varchar(50) DEFAULT NULL, `empowering_communities_name` text DEFAULT NULL, `empowering_communities_sign` text DEFAULT NULL, `empowering_communities_date` date DEFAULT NULL, `participant_enrolled_onto` varchar(50) DEFAULT NULL, `participant_moved_another_provider` varchar(50) DEFAULT NULL, `participant_eligible_free_school` varchar(50) DEFAULT NULL, `british_passport` varchar(225) DEFAULT NULL, `eec_passport` varchar(225) DEFAULT NULL, `euss_via_home` varchar(225) DEFAULT NULL, `preferred_evidence` varchar(225) DEFAULT NULL, `provide_preferred_evidence` varchar(225) DEFAULT NULL, `option_adoption_vertificate` varchar(225) DEFAULT NULL, `option_driving_licence` varchar(225) DEFAULT NULL, `option_non_eu_passport` varchar(225) DEFAULT NULL, `option_biometric_immigration` varchar(225) DEFAULT NULL, `option_current_immigration` varchar(225) DEFAULT NULL, `option_marriage_civil_partnership` varchar(225) DEFAULT NULL, `option_other_evidence` varchar(225) DEFAULT NULL, `option_nine` text DEFAULT NULL, `details_evidence_provided` varchar(225) DEFAULT NULL, `dwp_job_centre_letter` varchar(225) DEFAULT NULL, `confirmation_relevant_organisation` varchar(225) DEFAULT NULL, `self_certification_evidence` varchar(225) DEFAULT NULL, `partcipant_told_support` varchar(225) DEFAULT NULL, `participant_file_completed_remotly` varchar(225) DEFAULT NULL, `declaration_name_please_print` varchar(225) DEFAULT NULL, `declaration_job_title` varchar(225) DEFAULT NULL, `declaration_organisation` varchar(225) DEFAULT NULL, `declaration_signature_date` date DEFAULT NULL, `declaration_signature` varchar(225) DEFAULT NULL I can't see the issue anywhere Cheers, ED. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 11, 2023 Share Posted October 11, 2023 Do you have error display set and have you set the PDO error mode attrubute when connecting? eg $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); Â Quote Link to comment Share on other sites More sharing options...
EarthDay Posted October 11, 2023 Author Share Posted October 11, 2023 13 minutes ago, Barand said: Do you have error display set and have you set the PDO error mode attrubute when connecting? eg $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); Â Hi there, I have full error reporting on in my test environment but is not producing any error reports. I've tried a VARDUMP and comes back with; array(34) { ["id"]=> string(3) "151" ["learning_opportunities"]=> string(2) "No" ["contact_for_other_purposes"]=> string(5) "Phone" ["empowering_communities"]=> string(2) "No" ["empowering_communities_name"]=> string(22) "David Testffffffffffff" ["empowering_communities_sign"]=> string(9) "Dave Test" ["empowering_communities_date"]=> string(10) "2023-10-10" ["participant_enrolled_onto"]=> string(2) "No" ["participant_moved_another_provider"]=> string(2) "No" ["participant_eligible_free_school"]=> string(2) "No" ["british_passport"]=> string(3) "Yes" ["eec_passport"]=> string(2) "No" ["euss_via_home"]=> string(2) "No" ["preferred_evidence"]=> string(3) "Yes" ["provide_preferred_evidence"]=> string(9) "345345353" ["option_adoption_vertificate"]=> string(0) "" ["option_driving_licence"]=> string(0) "" ["option_non_eu_passport"]=> string(0) "" ["option_biometric_immigration"]=> string(0) "" ["option_current_immigration"]=> string(0) "" ["option_marriage_civil_partnership"]=> string(0) "" ["option_other_evidence"]=> string(0) "" ["option_nine"]=> string(35) "Utility Bill/Phone Bill/Council Tax" ["details_evidence_provided"]=> string(7) "sdghsdf" ["dwp_job_centre_letter"]=> string(0) "" ["confirmation_relevant_organisation"]=> string(0) "" ["self_certification_evidence"]=> string(3) "fff" ["partcipant_told_support"]=> string(3) "Yes" ["participant_file_completed_remotly"]=> string(2) "No" ["declaration_name_please_print"]=> string(7) "gdfgsdg" ["declaration_job_title"]=> string(8) "sdfgsdfg" ["declaration_organisation"]=> string(8) "sdfgsdfg" ["declaration_signature_date"]=> string(10) "2023-10-10" ["declaration_signature"]=> string(6) "dfgshf" } string(69) "No rows updated. Possible reasons: No changes detected or invalid ID." Cheers, ED. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 11, 2023 Share Posted October 11, 2023 Check the value of $_GET['id'] when you attempt the update. Why are you updating the clientid? Quote Link to comment Share on other sites More sharing options...
EarthDay Posted October 11, 2023 Author Share Posted October 11, 2023 8 minutes ago, Barand said: Check the value of $_GET['id'] when you attempt the update. Why are you updating the clientid? Hi there The outputs are string(3) "252" string(3) "151" which are correct. I thought it was an issue with the client_id and put in there for testing purposes. Will be removed when fixed. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 11, 2023 Share Posted October 11, 2023 Your earlier query checks for the existence of id = $_GET['decs_id']. Do not want to update that record? Quote Link to comment Share on other sites More sharing options...
maxxd Posted October 11, 2023 Share Posted October 11, 2023 The URL you say is your link to update is forms/decs-update.php?id=<?=$contact['id']?>&decs_id=<?=$decs['id']?>. Your form action is decs-update.php?id=<?=$decs['id']?>. To be honest, I don't recommend mixing methods like that. Just echo out the $contact['id'] and $decs['id'] as hidden fields in your form, then check the values using $_POST. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.