UPDATE not working with ajax?

0

The problem is this, I have an edit form whose data is sent by ajax . Here is the code:

$("#edit_rua").click(function(){
  var id = $(this).attr("data-id");
  var nome = $("#nome_rua2").val();
  var cod = $("#cod_rua").val();
  $.ajax({
      type: "POST",
      url: "cod_ajax/muda_rua.php",
      data: "id="+id+"&nome1="+nome+"&cod="+cod,
      success: function(e){
          alert(e);
          $(".nome"+id).html(nome);
          $(".cod"+id).html(cod);
      }
  })
});

I gave alert() in nome , it returns the value well, I gave alert inside muda_rua.php , it returns well, however, whenever it gives UPDATE , it does not update, only returns 0 , and if I type 1 , it inserts 1 .

Here is the code for muda_rua.php

<?php
require "ligacao_bd.php";
$nome=$_POST['nome1'];
$cod=$_POST['cod'];
echo $nome;
$insert=mysql_query("UPDATE nome_tabela SET nome = '$nome' AND cod_postal = '$cod' where id = '".$_POST['id']."'") or die("ERRO 1!!!");
?>

It does not give the error of mysql_error() , and if I remove the field from the name of UPDATE , it updates the zip code.

  

I know that mysql is deprecated but the old programmer used it and it has more than 100 pages to use it.

    
asked by anonymous 30.11.2017 / 18:40

1 answer

2

Your SQL is wrong, the error is because in SET the fields are separated by comma and the SQL of the query is AND , corrected example:

$insert=mysql_query("UPDATE nome_tabela SET nome = '$nome', cod_postal = '$cod' where id = '".$_POST['id']."'") or die("ERRO 1!!!");
    
30.11.2017 / 18:44