4
Basically the three scripts should edit a record in the Database:
php records.:
<?php
// Aqui você se conecta ao banco
$mysqli = new mysqli('127.0.0.1', 'root', '', 'login');
// Executa uma consulta
$sql = "SELECT `user_id`, `user_name` , `user_email` , `user_data` FROM `users`";
$query = $mysqli->query($sql);
while ($dados = $query->fetch_assoc()) {
$id = $dados["user_id"];
$nome = $dados["user_name"];
$email = $dados["user_email"];
$data = $dados["user_data"];
echo "<a href=\"editar.php?id=$id\">Editar </a>";
}
?>
edit.php:
<?php
// Aqui você se conecta ao banco
$mysqli = new mysqli('127.0.0.1', 'root', '', 'login');
// Executa uma consulta
$sql = "SELECT `user_id`, `user_name` , `user_email` , `user_data` FROM `admin_users`";
$query = $mysqli->query($sql);
while ($dados = $query->fetch_assoc()) {
$id = $dados["user_id"];
$nome = $dados["user_name"];
$email = $dados["user_email"];
$data = $dados["user_data"];
echo "
<form id=\"form1\" name=\"form1\" method=\"post\" action=\"salvar_edicao.php\">
<input name=\"id\" type=\"text\" readonly=\"readonly\" id=\"id\" value=\"$id\" size=\"35\"/><br>
<input name=\"nome\" type=\"text\" id=\"id\" value=\"$nome\" size=\"35\"/><br>
<input name=\"email\" type=\"text\" id=\"id\" value=\"$email\" size=\"35\"/><br>
<input name=\"data\" type=\"text\" readonly=\"readonly\" id=\"id\" value=\"$data\" size=\"35\"/><br>
<input type=\"submit\" onclick=\"return confirm('Deseja mesmo editar esse registro?');\" name=\"Submit\" value=\"SALVAR ALTERAÇÕES\" class=\"btnNew\"/>
</form>
";
}
?>
</div></div>
salvar_edicao.php:
<?php
$id = $_POST["id"];
$nome = $_POST["nome"];
$email = $_POST["email"];
$data = $_POST["data"];
// Aqui você se conecta ao banco
$mysqli = new mysqli('127.0.0.1', 'root', '', 'login');
mysql_query("UPDATE users SET user_name = '$nome', user_email = '$email' WHERE users.id = $id");
mysql_close();
header("Location: index.php#tabs-4");
?>
It doesn’t change. What’s wrong?
Note that your file saves.php creates a connection with MYSQLI ($mysqli = new mysqli('127.0.0.1', 'root', 'login');) and update tries to update with MYSQL (mysql_query("UPDATE users SET user_name = '$name', user_email = '$email' where users.id = $id");)
– adrianosymphony