I’m not able to save a data edit with php and mysql

Asked

Viewed 30 times

0

Save working properly

<?php include "conectar.php";
$nome="$_POST[nome]";
$sobrenome="$_POST[sobrenome]";
$email="$_POST[email]";
$cpf="$_POST[cpf]";
$dddcel="$_POST[dddcel]";
$cel="$_POST[cel]";
$dddtel="$_POST[dddtel]";
$tel="$_POST[tel]";
$nasc="$_POST[nasc]";

$sql->query ("insert into dados(nome, sobrenome, email, cpf, dddcel, cel, dddtel, tel, nasc) values ('$nome', '$sobrenome', '$email', '$cpf', '$dddcel', '$cel', '$dddtel', '$tel', '$nasc')");

header("Location: listar.php");
?>

And this is the one that’s not working:

<?php 
include "conectar.php";   //inlui o conectar(endereco do banco)
$nome=$_POST["nome"];
$sobrenome=$_POST["sobrenome"];
$email=$_POST["email"];
$cpf=$_POST["cpf"];
$dddcel=$_POST["dddcel"];
$cel=$_POST["cel"];
$dddtel=$_POST["dddtel"];
$tel=$_POST["tel"];
$nasc=$_POST["nasc"];

$sql->query("UPDATE dados SET nome ='$nome', sobrenome ='$sobrenome', email = '$email', cpf = '$cpf', dddcel = '$dddcel', cel = '$cel', dddtel = '$dddtel', tel = '$tel', nasc = '$nasc' where cod = $cod");

header("Location: listar.php");
?>
  • Where does the variable come from $cod? It contains value?

  • 1

    You have the syntax changed: $nome="$_POST[nome]"; must be $nome=$_POST["nome"]; in all variables.

  • Is there no error message? This would make it easier for us to help you.

1 answer

0

The syntax is wrong:

Wrong

$nome="$_POST[nome]";

Right

$nome = $_POST["nome"];

I don’t understand why you said that "Save" is working, and the syntax is wrong.

  • 2

    I think there was just his typo here, because where have this is in the file where he says it works. o. The

  • In the first code there is the possibility of having saved everything as STRING in the database (IF THE COLUMNS ARE SET TO RECEIVE STRING), if this did not happen it was an error. In the second missing the variable '$Cod'.

Browser other questions tagged

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