0
how can I check if a field in my bank column already exists? I tried so however it is not returning anything
error_reporting(E_ALL);
if(isset($_POST['adicionar'])&&$_POST['adicionar']=='adicionou'){
if(empty($_POST['nome'])){
echo 'Nome está vazio.';
}else{
$verificaDuplicados=$conn->prepare("SELECT `nome` FROM `noticias` WHERE `nome` = ".$_POST['nome']."") or die(mysqli_error());
$verificaDuplicados->execute();
$contaNoticia=$verificaDuplicados->rowCount($_POST['nome']);
if($contaNoticia>=1){
echo "ja existe";
}else{
echo "se a noticia nao existe faz o insert";
}
}
}
Try user
or die(mysqli_error())
in front of method callsprepare
,execute
androwCount
. It might show something related to the problem.– relaxeaza
@Rafaelmafra put the
or die(mysqli_error())
in theselect
he is ignoring the check whether or not there is a column in the bank– goio
Isn’t there a problem with the syntax of your code? It’s missing a Bracket from the first
if
.– relaxeaza
@Rafaelmafra I forgot to close the key that from the action in the boot to post the code here, I checked and all keys are closed correctly
– goio
Try closing the query value with simple quotes to form a string:
'".$_POST['nome']."'"
– relaxeaza
@Rafaelmafra worked, thanks little brother
– goio