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.
|