Jump to content

Confirm 2 fields belong to same record?


Ansel_Tk1

Recommended Posts

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

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

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.