UPDATE not working with ajax?

Asked

Viewed 42 times

0

The problem is this, I have an editing form whose data is sent by ajax. Here’s 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 a alert() in the nome, I gave him a alert within the muda_rua.php, returns well, however, whenever it gives the UPDATE, it does not update, just returns 0, and if I type 1, he inserts 1.

Here is the code of 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 postcode.

I know that the mysql is deprecated but the old programmer used it and he has over 100 pages using it.

1 answer

2


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

$insert=mysql_query("UPDATE nome_tabela SET nome = '$nome', cod_postal = '$cod' where id = '".$_POST['id']."'") or die("ERRO 1!!!");
  • Thank you! It worked, I will give your reply as accepted soon. I could explain why it did not give error in mysql?

  • @I_like_trains this gives error or can not be some configuration on PHP.

Browser other questions tagged

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