ok so how do i work out this problem:
i am trying to catch this error in a php webapp that captures input
data from a user. im using php and pgsql on mypgadmin, sourcecode column
constraints : “CONSTRAINT sourcecodes_sourcecode_key UNIQUE (sourcecode)”
ERROR
Warning: pg_execute() [function.pg-execute]: Query failed: ERROR:
duplicate key value violates unique constraint
“sourcecodes_sourcecode_key” DETAIL: Key (sourcecode)=(Source3) already
exists. in D:\xampp\htdocs …php on line 289
Problem when user enters an existing sourcecode then the error is generated on POSTING the value.
Code
if(array_key_exists(“btnsubmit”, $_POST)) {
$pk_check = “true”;
if($pk_check == "true") {
$parameters = array();
$parameters[] = $counter;
$parameters[] = $_POST['source'];
$sql_string = "INSERT INTO config.sourcecodes (id,sourcecode ) VALUES ($1,$2 )";
try {
$saved = $db_cfg->Execute($sql_string, "", $parameters);
if($saved) {
$feedback = 'New Campaign: ' . $_POST['campaign_id'] . ' Saved successfully';
} else {
error_reporting(32);
$feedback = "_Error Saving Source Code ! _";
//echo pg_last_notice($sql_string) ;
// throw new $exception('Error saving new source code');
}
}
catch(\sdException $exception) {
throw new Exception('fatal err trycatch nt wrkn');
}