0
In this Sert below only works until the first rule of "Where" then no longer works
Example
WHERE descricao ='$ccusto' // funciona perfeitamente. Mas se uso o where abaixo
WHERE descricao ='$ccusto' AND id_transfer ='$id_transfer' AND id_empresa='$id_empresa')");
// já não funciona
echo $id_transfer22 = 555;
echo $id_empresa = 555;
echo $ccusto = 'obaoba';
echo $id_novo8= 555;
$sql = mysql_query ("INSERT INTO c_custo(id_transfer,id_empresa,descricao,cod)
SELECT '$id_transfer22','$id_empresa','$ccusto','$cod'
FROM DUAL
WHERE NOT EXISTS(SELECT descricao,id_empresa,id_transfer FROM c_custo
WHERE descricao ='$ccusto' AND id_transfer ='$id_transfer' AND id_empresa='$id_empresa')");
What could I be doing wrong?
Opa, reading again the question I understood what you want: Do INSERT of what comes in SELECT in table c_cost, using Where the first way works and the second way does not and want to correct to get the second way too.
– Antonio Alexandre
Put this query in a variable, echo it on the screen and run it straight to the seat. Try SELECT alone to see if something is coming. My guess is that when you include these more details there is no record in the bank satisfying this query.
– Antonio Alexandre
Hello Putting the query in mysql is working perfectly returns 5 reptilian items, therefore it should not accept the Insert because it already has equal records
– Fabio Henrique
Check out Mike’s answer in this Soen topic: http://stackoverflow.com/questions/3164505/mysql-insert-record-if-not-exists-in-table
– Antonio Alexandre