PHP UPDATE runs but does not update

Asked

Viewed 73 times

2

Good night!! I am developing an application in college, as requested by the teacher. Initially we were asked to do a CRUD. Of all the operations, the only one I could not get was the update. I get the impression that the registry ID is not being recovered. Could someone help me? Follow codes:

Update.php

<?php
  //update.php
   include_once ("conectar.php");

    $name = $_POST["name"];
    $email = $_POST["email"];
    $id = $_POST["id"];

  
    $sql = "UPDATE pessoa SET PessoaNome='$name', PessoaEmail='$email'item.PessoaId = ".$id;
  
    if(mysqli_query($conexao,$sql)){
        $msg = "Atualizado com sucesso!";
    }else{
        $msg = "Erro ao atualizar!";
    }
    mysqli_close($conexao);    
      
    ?>

html register.

<div class="page" data-name="cadastro">
  <div class="navbar">
    <div class="navbar-inner sliding">
      <div class="left">
        <a href="#" class="link back">
          <i class="icon icon-back"></i>
          <span class="ios-only">Voltar</span>
        </a>
      </div>
      <div class="title">Pessoa</div>
    </div>
  </div>
  <div class="page-content">
    <form class="list" action="cli.php" method="POST">
      <ul>
        <li>
          <div class="item-content item-input">
            <div class="item-inner">
              <div class="item-title item-label">ID</div>
              <div class="item-input-wrap">
                <input type="hidden" name="Pessoaid" id="idPessoa" placeholder="id">
              </div>
            </div>
          </div>
        </li>
        <li>
          <div class="item-content item-input">
            <div class="item-inner">
              <div class="item-title item-label">Nome</div>
              <div class="item-input-wrap">
                <input type="text" name="name" id="NomePessoa" placeholder="Your name">
              </div>
            </div>
          </div>
        </li>
        <li>
          <div class="item-content item-input">
            <div class="item-inner">
              <div class="item-title item-label">E-mail</div>
              <div class="item-input-wrap">
                <input type="email" name="email" id="EmailPessoa" placeholder="E-mail">
              </div>
            </div>
          </div>
        </li>
        <div class="item-content">
          <div class="item-inner">
            <div class="item-title">Toggle</div>
            <div class="item-after">
              <label class="toggle toggle-init">
                                    <input type="checkbox" name="toggle" value="yes"><i class="toggle-icon"></i>
                                </label>
            </div>
          </div>
        </div>
        </li>
      </ul>
    </form>
    <div class="block">
      <div class="row">
        <input class="col button button-fill" name="excluir" type="submit" id="excluir" value="Excluir!" />
        <input class="col button button-fill" name="salvar" type="submit" id="salvar" value="Salvar!" />
      </div>
    </div>
  </div>

Ws.js

function atualizaPessoa(id){
	$.ajax({
		type: "POST",
		crossDomain: true,
		url: 'http://localhost/appaula/ws/update.php?id='+id,
		dataType: "text",
		async: false,
		success: function (result) {
			app.dialog.alert("Atualizado com sucesso");
		},
		error: function() {
			app.dialog.preloader('Erro ao atualizar pessoas');
		},
	});
}

I’m sorry, but I’m pretty new at this, so forgive me for anything. Thanks in advance!!!

  • Hello, Good night!!! cli.php would be update.php, whereas Ws.js specifically Function actualizepessoa is being called at page startup, via this code snippet below, which would run the updater at the moment the user clicks to save.

  • $$(Document). on('page:init', '.page[data-name="register"]', Function(e) { returnPessoa(idPessoa); $('#delete').click(Function(){ app.dialog.confirm('Delete Registration??', Function() { deletePessoa(idPessoa); app.dialog.Alert('Done!'); }); }); $('#save').click(Function(){ updatePessoa(idPessoa); }); });

  • syntax error in UPDATE declaration

1 answer

0


Hello, Locate the following line of your code:

$sql = "UPDATE person SET Personal Name='$name', Personal;

Replace it with something like this: $sql = "UPDATE person SET Personname='$name', Personemail='$email' WHERE Personid='$id'";

This should make the update work, Abçs.

  • Thanks for the reply, it worked correctly after performing the suggested adjustment!!!

Browser other questions tagged

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