I am trying this:
<?php
session_start();
require 'conexion.php';
$nombre = $_POST['nombre'];
$emai = $_POST['emai'];
$pass = $_POST['pass'];
$tel = $_POST['tel'];
$dir = $_POST['dir'];
$id = $_SESSION['usuario']['ID'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Oops: " . $conn->connect_error);
}
if (isset($_SESSION['usuario'])) {
$cambio = "UPDATE Usuarios SET name='$nombre', email='$emai', password='$pass', phone='$tel', address='$dir' WHERE ID='$id'";
if (($result=$conn->query($cambio)) === true) {
echo $_SESSION['usuario']['name'];
} else {
echo "Error: ";
}
} else {
echo"oops";
}
$conn->close();
?>
With this form:
<form action="vcambio.php" method="post">
<div class="group">
<input type="text" name="nombre" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>cambiar nombre</label>
</div>
<div class="group">
<input type="email" name="emai" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Cambiar Email</label>
</div>
<div class="group">
<input type="password" name="pass" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Cambiar Contraseña</label>
</div>
<div class="group">
<input type="text" name="tel" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Cambiar Telefono</label>
</div>
<div class="group">
<input type="text" name="dir" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Cambiar direccion</label>
</div>
<input type="submit" name="sumbitt" value="Guardar Cambios"</input>
</form>
<?php
if (isset($_POST['submitt'])) {
require ("vcambio.php");
}
?>
I don't find the error when I run it. Prints the variables from the previous session. It does not throw me an error but it does not update the variables, when I consult it in it it phpmyadmin
continues the same as before.
You would have to pass a user ID per session ... so that the update of your WHERE is governed there (where your little problem is)
In the code you passed, there is no "$email" variable, but "$emai"
(---Approach---) If I have all my data and as email "[email protected]" I want to change it to "[email protected]" in your WHERE it will look for the email [email protected] to change it by [email protected] and it will not look for [email protected] (depending on the query you are using, unless you save its current email as session or pass it through input hidden (which is later implemented in a few more lines to control that they do not manipulate it before sending it to php+sql))
However, since I can't see the connection.php file, it's impossible to find out if the connection is right...
I hope I helped you.
Cheers
Another error apart from those that have been modified by the comments is in the following step:
I see too many open and close braces
()
, in fact I did a test, and it sends me an error.You could do something like this:
either
A possible example:
connection.php
UPDATE
I suggest you try this solution. In her:
$arrMensaje
, which is printed at the end to tell you what happened in the code. I call this principle controlled code . I believe that the programmer should never write code that fails without him knowing why it fails. Here he will tell you anything.ID
is all capitalized?. Note that table and column names are case sensitive . Well, if you have it misspelled you will know, the code will tell you.ID
is of type VARCHAR in the database or if it is numeric...With that said, here we go. I hope you can try it and comment the result: