Custom Error message on sc_exec_sql failure?

I am doing a mysql insert during a form load.
But it is possible for the key for the table to already be there.
I am trying to just throw up an error message to let the user know he cant add that already.

all I am is getting this…

ERROR
Error while accessing the database:
Duplicate entry ‘1-2’ for key ‘PRIMARY’

How do I throw an message to the user?

Kev

Hi,
since you don’t get a return value from the sc_exec_sql() macro, I suggest using the sc_select() macro. Don’t let you fool by the name.

sc_select(success,“Insert …”);
if($success === false)
{
echo “<script>alert(‘Ooops!’);</script>”;
}

jsb

That works…
Would have liked to make it a little better looking but it solves the duplicate mysql error…
Thanks…

Kev

Instead of using the alert() function you can also redirect to a modal control application. Then you have all sorts of visual design options.

jsb

This my code how to modify it to avoid display duplicate error message:
if(count([selected]) > 0)
{
$to_copy = implode(’,’,[selected]); //"(".implode(’,’,[selected]).")";
$sql = “INSERT INTO Emp_Accommodate (EmployeeNo, NameAr, Nationality_Ar, JobActual_Name, Project_Name, IqamaID_No, PassportNo, TelNo, Shift_Type, Room_IDF, House_IDF) SELECT EmployeeNo, NameAr, Nationality_Ar, JobActual_Name, Project_Name, IqamaID_No, PassportNo, TelNo, Shift_Type, Room_IDF, House_IDF FROM Employee WHERE EmployeeNo =’$to_copy’”; //replace multi_add with your table name and replace name, list with a listing of your table entries that you need to copy. Must match order of your database
sc_exec_sql($sql);
[selected] = array();
}

Thanks in advance