CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Solution - Foreign Key Constraints- Trap Constraint Errors

Print topic Send  topic

Author Message
bej34

Posts: 14
Posted: 06/07/2006, 7:49 AM

:-) I think that I have found a solution for the old foreign key constraint errors, a way to make them user friendly.

Step 1: On the record form Insert a hidden file field labeled my_id. You should connect this field to the database and give it the value of the primary key for your table.

Step 2: You should highlight (or select) the record form and change the Custom Insert and Custom Update to table and delete the my_id control (field) from the list of places to get the values for your SQL statement.

Step 3: Add a custom code action on the Before Delete event. When the custom code page loads insert the code below and change it according to your page.

$secwhere = $your_form_name->my_id->GetValue();
$dbb = new clsDBYourDatabaseName();
$fkcheck = CCDLookUP("column","table","primary_key = $secwhere",$dbb);
if($fkcheck !== "") {
//Modify the HTML Below to fit your page. You can modify the colors and definitely modify the pictures. I left the pictures
//in to show you how to insert them, they can definitely be removed if you don't need them. The links to the child records
//can also be removed or modified. Good Luck
$your_form_name->Errors->addError("<font color=\"0066CC\"><img src=\"images/FK_notice.jpg\" alt=\"Notice Flag - Click here to find out what this means\"><strong>CHILD RECORD ERROR</strong> - This record cannot be deleted because it has a dependent question(s) - Dependent <a href=\"questions.php?kb_qid=$fkcheck\"><strong>Question ID - $fkcheck</strong></a><br>You must find the question <a href=\"questions.php?kb_qid=$fkcheck\"><strong>(Question ID - $fkcheck)</strong></a> and update or delete it before deleting this department.</font>");
$your_form_name->DeleteAllowed = false;
}

I hope this code helps someone it sure helped my project. Glad to contribute. If you find some bugs please feel free to post them.
_________________
"SELF PROCLAIMED PHP + CODECHARGE STUDIO EXPERT"
CODECHARGE STUDIO HAS CHANGED MY LIFE!! I GET MORE WOMEN AND OLD PEOPLE LOVE ME NOW!!! YAAAY!! -- http://www.ipoots.com
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.