My php code UPDATE code doesn't work. There are no error messages it doesn't update. Here is the code:
<?php require 'connections/connections.php'; ?>
<?php
session_start();
if(isset($_SESSION["UserIdent"])){
}else{
header('Location: login.php');
}
?>
<?php
$User = $_SESSION["UserIdent"];
$result = $con->query("select * from user where UserID='$User'");
$row = $result->fetch_array(MYSQLI_BOTH);
$_SESSION["FirstName"] = $row['Fname'];
$_SESSION["LastName"] = $row['Lname'];
$_SESSION["Username"] = $row['Username'];
$_SESSION["Email"] = $row['Email'];
$_SESSION["Password"] = $row['Password'];
?>
<?php
if(isset($_POST['UpdateUser'])){
$UpdateFname = $_POST['FirstName'];
$UpdateLname = $_POST['LastName'];
$UpdateUsername = $_POST['Username'];
$UpdateEmail = $_POST['Email'];
$UpdatePassword = $_POST['Password'];
$sql = $con->query("UPDATE user SET Fname = '{$UpdateFname}',
Lname = '{$UpdateLname}',
Email = '{$UpdateEmail}',
Username = '{$UpdateUsername}',
Password = '{$UpdatePassword}',
where UserID= $User");
header('Location: UpdateAccount.php');
}
?>
The HTML code is here:
<!doctype html>
<html>
<head>
<link href="css/Master.css" rel="stylesheet" type="text/css">
<link href="css/Menu.css" rel="stylesheet" type="text/css">
<meta charset="utf-8">
<title>UpdateAccount</title>
</head>
<body>
<div id="holder">
<div id="header"></div>
<div id="NavBar">
<nav>
<ul>
<li><a href="account.php">Account</a></li>
<li><a href="Logout.php">Logout</a></li>
</ul>
</nav>
</div>
<div id="Content"></div>
<div id="ContentLeft"></div>
<div id="ContentRight"><form> <h6>
<label for="FirstName">First Name:<br>
</label>
<input name="FirstName" type="text" required="required"
class="StyleTxtField" id="FirstName" value="<?php echo
$_SESSION["FirstName"]; ?>">
</h6>
<h6>
<label for="LastName">Last Name:<br>
</label>
<input name="LastName" type="text" required="required" class="StyleTxtField"
id="LastName" value="<?php echo $_SESSION["LastName"]; ?>">
</h6>
<h6>
<label for="Username">Username:<br>
</label>
<input name="Username" type="text" class="StyleTxtField" id="Username"
value="<?php echo $_SESSION["Username"]; ?>">
</h6>
<h6>
<label for="Email">Email:<br>
</label>
<input name="Email" type="text" required="required" class="StyleTxtField"
id="Email" value="<?php echo $_SESSION["Email"]; ?>">
</h6>
<h6>
<label for="Password">Password:<br>
</label>
<input name="Password" type="password" class="StyleTxtField" id="Password"
value="<?php echo $_SESSION["Password"]; ?>">
</h6>
<p>
<input name="UpdateUser" type="submit" class="StyleTxtField" id="UpdateUser"
value="UpdateUser">
</p>
</form></div>
<div id="Footer"></div>
</body>
</html>
The Problem is that I can't figure out why it isn't updating...Any Help I would be grateful. There are no errors so it should work fine but it doesn't.I just learning Mysqli so any security issues I am not worried about yet, all I want is help on how to get this code to work. Thanks!
In your code there is no method defined in <form>
You are using $_POST
super global for fetching values. So your form method must be post as like:
<form method="post">
UPDATE 1
As my other friend Fred-ii suggest please make sure you are using session_start()
in other files aswell where you need the information from $_SESSION
specially in this file where you redirect the user
UpdateAccount.php
Most important issues:
why are you saving password in session? And if its simple text no any encrypted function than its another issue. You need to save password in encrypted format.
you need to prevent your code from SQL Injection.
one more issue identified by @fred-ii remove ending comma from this line
Password = '{$UpdatePassword}',
Side note:
Always active your error_reporting
on development side not on production. You will get all the errors and save your time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.