check if column already exists in the bank

Asked

Viewed 32 times

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";
    }
  }
}
  • 1

    Try user or die(mysqli_error()) in front of method calls prepare, execute and rowCount. It might show something related to the problem.

  • @Rafaelmafra put the or die(mysqli_error()) in the select he is ignoring the check whether or not there is a column in the bank

  • 1

    Isn’t there a problem with the syntax of your code? It’s missing a Bracket from the first if.

  • @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

  • 1

    Try closing the query value with simple quotes to form a string: '".$_POST['nome']."'"

  • @Rafaelmafra worked, thanks little brother

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.