Drcox
|
Posted: 02/23/2006, 1:22 PM |
|
I am trying to prevent the following error...
MySQL Error: 1062 (Duplicate entry 'me@mymail.org-20-Lane' for key 2)
Session halted.
MySQL database as a unique index for the 3 following fields...
email, streetno, & streetname.
The generated code for validating each field separately is provided below. I need to combine the 3 into one single statement.
I am using codecharge 2.0.7 PHP 4.0 w/ templates.
Does anyone know how to do this? Thanks!!!
if(strlen($fldemail) )
{
$iCount = 0;
if($sAction == "insert")
$iCount = get_db_value("SELECT count(*) FROM members WHERE email=" . tosql($fldemail, "Text"));
else if($sAction == "update")
$iCount = get_db_value("SELECT count(*) FROM members WHERE email=" . tosql($fldemail, "Text") . " and not(" . $sWhere . ")");
if($iCount > 0)
$sNewtempErr .= "The value in field E-mail* is already in database.<br>";
}
if(strlen($fldstreetname) )
{
$iCount = 0;
if($sAction == "insert")
$iCount = get_db_value("SELECT count(*) FROM members WHERE streetname=" . tosql($fldstreetname, "Text"));
else if($sAction == "update")
$iCount = get_db_value("SELECT count(*) FROM members WHERE streetname=" . tosql($fldstreetname, "Text") . " and not(" . $sWhere . ")");
if($iCount > 0)
$sNewtempErr .= "The value in field streetname is already in database.<br>";
}
if(strlen($fldstreetno) && is_numeric($fldstreetno))
{
$iCount = 0;
if($sAction == "insert")
$iCount = get_db_value("SELECT count(*) FROM members WHERE streetno=" . tosql($fldstreetno, "Number"));
else if($sAction == "update")
$iCount = get_db_value("SELECT count(*) FROM members WHERE streetno=" . tosql($fldstreetno, "Number") . " and not(" . $sWhere . ")");
if($iCount > 0)
$sNewtempErr .= "The value in field streetno is already in database.<br>";
|
|
|
|