Ansel_Tk1 Posted June 11, 2008 Share Posted June 11, 2008 Hi - wondering if some kind soul out there can help me. I am using Adobe's Dreamweaver Development Toolbar to create a registration page for my website. I realize that ADDT is not only PHP, but my question is about a PHP function in my script I need to change and I'm not sure how to make the change. I'm trying to create a custom trigger that confirms 2 fields belong to the same record. If they do, proceed with insert transaction. The script below works fine as a check to see whether there is already a record in the table with both the family_id and confirm_id within and stops the transaction if true (to prevent a duplicate entry). I'd like to check to see if both family_id and confirm_id are within the same record. If they are not, stop the transaction and . If they are, proceed. Can anyone help me to change the script here to confirm that both fields belong to the same record? Here is what I have right now: $query = "SELECT * FROM dan_camptrans_login_familyid_confirmid WHERE family_id = ".KT_escapeForSql($tNG->getColumnValue("family_id"),$tNG->getColumnType("family_id"))." AND confirm_id = ".KT_escapeForSql($tNG->getColumnValue("familyconfirm_id"),$tNG->getColumnType("familyconfirm_id")); $result = $tNG->connection->Execute($query); if(!$result) { $error = new tNG_error("Could not access database!",array(),array()); return $error; } else { if($numberOfRecords = $result->recordCount()) { $uniqueFailed = new tNG_error("There is already a message with the same subject and content!",array(),array()); return $uniqueFailed; } else { return NULL; } } Thank you Dan Link to comment https://forums.phpfreaks.com/topic/109736-confirm-2-fields-belong-to-same-record/ Share on other sites More sharing options...
craygo Posted June 11, 2008 Share Posted June 11, 2008 What you have should do it. Anytime you use AND in the WHERE clause you want both values to be compared in each row. Why do you think it does not work?? Ray Link to comment https://forums.phpfreaks.com/topic/109736-confirm-2-fields-belong-to-same-record/#findComment-563124 Share on other sites More sharing options...
Ansel_Tk1 Posted June 11, 2008 Author Share Posted June 11, 2008 Hi Ray - thank you so much for taking the time to look at my post. Right now, if I fill out the form and enter any numbers in the family_id and familyconfirm_id fields that are currently NOT in the table, the form submits fine. If however, both fields already exist within the same record, the error is returned. I guess what I am looking for is the opposite. When the form is submitted, the table dan_camptrans_login_familyid_confirmid is checked. If both field entries are not within the same record, return the error. Basically, I am sending out a user ID and confirmation number via mail to users. When they register they need to enter in both of these numbers and only if they match the records will the registration proceed. Thanks again - I hope that I am explaining this clearly. Dan Link to comment https://forums.phpfreaks.com/topic/109736-confirm-2-fields-belong-to-same-record/#findComment-563161 Share on other sites More sharing options...
craygo Posted June 11, 2008 Share Posted June 11, 2008 Well what you want to do is check and see if only ONE record is returned rather than comparing the number of record to the result. Looks like you are using a class for you database functions so you will have to change some things <?php $query = "SELECT * FROM dan_camptrans_login_familyid_confirmid WHERE family_id = ".KT_escapeForSql($tNG->getColumnValue("family_id"),$tNG->getColumnType("family_id"))." AND confirm_id = ".KT_escapeForSql($tNG->getColumnValue("familyconfirm_id"),$tNG->getColumnType("familyconfirm_id")); $result = $tNG->connection->Execute($query); if(!$result) { $error = new tNG_error("Could not access database!",array(),array()); return $error; } else { if($result->recordCount() == 1) { // run code to proceed below } else { // run code to error } } ?> Ray Link to comment https://forums.phpfreaks.com/topic/109736-confirm-2-fields-belong-to-same-record/#findComment-563171 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.