Hi,
I am trying to find if a presenting author in a database is already in my table 'presenting_authors' to avoid a duplicate entry once the user submits the form.
So in order to achieve this, I made the following function:
function find_duplicate_presenting_author($Prefix, $Last_Name, $First_Name, $Institution, $Department, $Address_Line_1, $Address_Line_2, $City, $Prov_ST_ID, $Country_ID, $ZIP_Postal_Code, $Phone_Country_Code, $Phone, $Fax_Country_Code, $Fax, $E_Mail) {
$query = "SELECT Presenting_Author_ID
from Presenting_Authors
WHERE Prefix = '".mysql_real_escape_string($Prefix)."' and Last_Name = '".mysql_real_escape_string($Last_Name)."' and First_Name = '".mysql_real_escape_string($First_Name)."' and Institution = '".mysql_real_escape_string($Institution)."' and Department = '".mysql_real_escape_string($Department)."' and Address_Line_1 = '".mysql_real_escape_string($Address_Line_1)."' and Address_Line_2 = '".mysql_real_escape_string($Address_Line_2)."' and City = '".mysql_real_escape_string($City)."' and Prov_ST_ID = '".mysql_real_escape_string($Prov_ST_ID)."' and Country_ID = '".mysql_real_escape_string($Country_ID)."' and ZIP_Postal_Code = '".mysql_real_escape_string($ZIP_Postal_Code)."' and Phone_Country_Code = '".mysql_real_escape_string($Phone_Country_Code)."' and Phone = '".mysql_real_escape_string($Phone)."' and Fax_Country_Code = '".mysql_real_escape_string($Fax_Country_Code)."' and Fax = '".mysql_real_escape_string($Fax)."' and E_Mail = '".mysql_real_escape_string($E_Mail)."'";
$result = mysql_query($query);
if( !( $result = mysql_query( $query ) ) ){
return 1;
}
list( $id ) = mysql_fetch_row( $result );
return $id;
}
Now as you can see, there is alot of fields passed to the functions. Could there be a way for me to shorten the code somehow? I find it very long and tedious and I would like to adapt it with other fields also....
Anyone can suggest something? Thansk in advance! 🙂