How to Update mysqli Database Table with UPDATE?

Asked

Viewed 5,981 times

1

I am creating a data listing system, and created a data change page, with 6 fields, name, experience, email, phone, city and biography. only that my function does not update the fields. The data arrives in the function alter data() but does not update in the database.Only the experience field updates.

 function Altera_Dados(){
  $retorno="";
  $conecta = DBConnect();

  if(isset($_POST["atualiza"])){        
        $Nome = $_REQUEST['DadoNome']; 
        echo $_REQUEST['DadoNome'];
        $experiencia = $_POST['experiencia'];
        echo $_POST['experiencia'];
        $email = $_POST['email'];  
        echo $_POST['email'];     
        $telefone = $_POST['telefone'];
        echo $_POST['telefone'];
        $cidade = $_POST['cidade'];
        echo $_POST['cidade'];
        $id = $_POST['id'];
    //$biografia = $_POST['biografia'];

        $query ="UPDATE cadastro3 SET nome = '$Nome',experiencia='$experiencia',email='$email' where id ='$id'";
        $retorno = mysqli_query($conecta,$query)or die ('Erro na consulta ::. '. mysqli_error($conecta));
     }
  DBClose($conecta);
  return $retorno;
}

I used the ID ai the following message appears: mysqli_num_rows() expects Parameter 1 to be mysqli_result, Boolean Given in C: xampp htdocs Constructesfree Dozero System funcoes.php on line 284 Warning: Not updated!

  • 2

    Better yet. This code is extremely insecure. I notice that no one validates anything, no one cares if it’s right, just wants to see it working. Then there is no point in fixing a problem. Actually if solving this problem is worse because the person will think that now is ok.

  • Now we are on track. there is an error in your query!

1 answer

1


Try for the ID. The problem may be in Where. You must be looking for something that does not exist:

$up = mysql_query("UPDATE cadastro3 SET nome ='$Nome',experiencia='$experiencia',email='$email' WHERE id=$id");

if(mysql_affected_rows() > 0){
  echo "Sucesso: Atualizado corretamente!";
}else{
  echo "Aviso: Não foi atualizado!";
}

mysql_close($conexao);
  • but for this he must pass the ID as POST as well

  • Then let it pass.

  • kkkkkk calm boy I just told him not to have problems

  • 1

    Sorry @Victor didn’t mean to be ignorant.

  • 1

    thanks I am testing . then I will implement security, the important now is to work

  • Consegiu @Hamiltonventura ?

  • Yes I got is updating all the fields right, I think it was the "id" same. but this message keeps popping up: Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result, Boolean Given in C: xampp htdocs Constructesfree Dozero System funcoes.php!

Show 2 more comments

Browser other questions tagged

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