CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 [TIP] Multiple Unique Field Validation & Custom Error Message

Print topic Send  topic

Author Message
MichaelMcDonald

Posts: 640
Posted: 10/02/2010, 1:42 AM

I have 2 fields (userid, siteid) in the form (userassign3) and I would like to see if they exist in the same row in a table.


Take the 2 text field values from the form and get them as parameters. (CCGetParam).
These parameters form the SQL WHERE arguments.
If they are both found in a row then that rows keyid (in this example iduserassign) must be > 0.

If iduserassign > 0 then generate an error message.

In the form on validate event, custom code:


$db = new clsDBFM();

$SQL = "SELECT iduserassign FROM userassign WHERE userid=" . $db->ToSQL(CCGetParam("iduser"),ccsInteger).
"."."AND siteid=" . $db->ToSQL(CCGetParam("siteid"),ccsInteger);
$db->query($SQL);

if($db->next_record()) {
$iduserassign = $db->f("iduserassign");
}

$db->close();

if ($iduserassign > 0)
{
$userassign3->Errors->addError("User Assignment Already In Database");
}

------------------------------------------------------------------------------------
A little more on this topic:

If your WHERE variables are a mix of integers and text values, make sure to use the integer first in the WHERE...

_________________
Central Coast, NSW, Australia.

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.