0
Good I’m with the following problem I’m making a conditional Insert not to duplicate entries in the table but is not inserting me anything
Code
<?php
session_start();
if(isset($_SESSION['user_id'])){
mysql_query("INSERT INTO visitas_estabelecimento (user_id, estabelecimento_id) VALUES ('".$_SESSION['user_id']."', '".$row_cat->id."')
WHERE NOT EXISTS
(SELECT * FROM visitas_estabelecimento
WHERE estabelecimento_id='".$row_cat->id."' and user_id='".$_SESSION['user_id']."'");
}
?>
$row_user_id=mysql_fetch_object($result_verifica);
$_SESSION['user_id'] = $row_user_id->id;
Have you checked if the output of the string you are running inside the
mysql_query
is returned as expected? Probably some variable is empty. If you have everything ok, run the command in someSGBD
and see what happens– Lucio Rubens
Yes I have checked and leave as expected
– César Sousa
Could put the code where
$_SESSION['user_id']
is initialized;– rray
I already put not put everything because I would have to put the whole login
– César Sousa
If help I printed the return of the query INSERT INTO visitas_establishment (user_id, estabelecimento_id) VALUES (38, 1) WHERE NOT EXISTS (SELECT * FROM visitas_establishment WHERE estabelecimento_id=1 and user_id=38)
– César Sousa