manju70
asked on
trapping mysql_errno() & updating db
hai all,
my intention is to trap mysql_errno while I try to insert data in to mysql. the coding is as below
$addStmt = //sql query for insert statements
if(!($val= mysql_query($addStmt)) && (mysql_errno()=1062)){
$addStmt1="update $tableName3 set $tableName3.dop_dbb
=$value4";
mysql_query($addStmt1) or die(mysql_error());
}//if statement is to trap for duplicate key in db
elseif(!($val= mysql_query($addStmt))){my sql_query( $addStmt1) ;
echo mysql_error();
}// this if statement is to trap other errors
else{
mysql_query($addStmt) or die (mysql_error());
echo "success";
}// this is for inserting in to db if other if clauses r turns false.
here I my problem is I get an error msg in my first if statement.
is anything wrong with my coding.
please let me know.
thanks
my intention is to trap mysql_errno while I try to insert data in to mysql. the coding is as below
$addStmt = //sql query for insert statements
if(!($val= mysql_query($addStmt)) && (mysql_errno()=1062)){
$addStmt1="update $tableName3 set $tableName3.dop_dbb
=$value4";
mysql_query($addStmt1) or die(mysql_error());
}//if statement is to trap for duplicate key in db
elseif(!($val= mysql_query($addStmt))){my
echo mysql_error();
}// this if statement is to trap other errors
else{
mysql_query($addStmt) or die (mysql_error());
echo "success";
}// this is for inserting in to db if other if clauses r turns false.
here I my problem is I get an error msg in my first if statement.
is anything wrong with my coding.
please let me know.
thanks
if(!($val==mysql_query($ad dStmt)) && (mysql_errno()==1062)){
ASKER
hai all,
thanks for locating my error.(mistake)
I have addtional query pertaining to above code.
as I mentioned earlier.
1) first if to trap mysql_errno()=1062
2) 2nd if is to check for any other errors other than above condition
3) 3rd is if nothing happens for above 2 condition just insert the values in to db instead of updating.
can anyone tell me the way I check my 2nd & 3rd condition is correct or is there any better way of putting my conditions.
thanks
thanks for locating my error.(mistake)
I have addtional query pertaining to above code.
as I mentioned earlier.
1) first if to trap mysql_errno()=1062
2) 2nd if is to check for any other errors other than above condition
3) 3rd is if nothing happens for above 2 condition just insert the values in to db instead of updating.
can anyone tell me the way I check my 2nd & 3rd condition is correct or is there any better way of putting my conditions.
thanks
Try this
$addStmt = //sql query for insert statements
$val=mysql_query($addStmt) ;
if(!($val) && mysql_errno()==1062){
}
$addStmt = //sql query for insert statements
$val=mysql_query($addStmt)
if(!($val) && mysql_errno()==1062){
}
To trap 1062 errors AND if other error display error and exit do but if NO errors enter information do:
$addStmt = //sql query for insert statements
if(!($val=mysql_query($add Stmt)))
{
//Check if error is 1062
if(mysql_errno() == 1062)
{
trap error
}
else //If error but not 1062 display error and terminate
{
echo mysql_error();
exit;
}
}
$addStmt = //sql query for insert statements
if(!($val=mysql_query($add
{
//Check if error is 1062
if(mysql_errno() == 1062)
{
trap error
}
else //If error but not 1062 display error and terminate
{
echo mysql_error();
exit;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I wanted to share the marks between andriv & harwantgrewal.
how to do?
how to do?
if(!($val= mysql_query($addStmt)) && (mysql_errno()==1062))
Harry