Change this line:
if(!(mysql_query($grava,$conn))){
to this:
if($grava === false) {
The function mysql_query is setting $grava to a boolean value, depicting the success of the query in the function. Hence your if statement needs to check the value of $grava to know whether or not the query was successful.