i'm having problems in executing a query inside php. I have the following query in my php code:
$nome = pg_escape_string($_POST['cnome']);
$obtem_idb = "SELECT idb FROM banda WHERE nome = $nome";
echo("$nome");
$idb = pg_query($connection, $obtem_idb);
if(!$idb){
die("Error in SQL query: " . pg_last_error());
} else {
echo("o idb que vem da query é $idb");
}
The name i print is correct, but when trying to execute the query i get the following error:
Error in SQL query: ERROR: column "anthrax" does not exist LINE 1: SELECT idb FROM banda WHERE nome = Anthrax ^
Can anyone help, i can't seem to find the error.
When i put the variable $nome in single quotes the value of it changes to 'Resource id #2' and i get the following error:
Error in SQL query: ERROR: insert or update on table "edicao" violates foreign key constraint "edicao_idb_fkey" DETAIL: Key (idb)=(Resource id #2) is not present in table "banda".