Hello I have a query for updating the information of the user but it does not do anything. How can I solve this? Please Help.
Here is the html code.
<?php
$sql = "SELECT * FROM users ";
$query = $conn->query($sql);
$row = $query->fetch_array();
?>
<form action="account_edit_script.php" method="POST">
<div class="form-group">
<label class="d-flex justify-content-center"><strong>Update Information</strong></label>
<label>Fullname</label>
<input type="text" name="user_fullname" value="<?php echo $row['user_fullname']; ?>" class="form-control" placeholder="" required>
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="user_email" value="<?php echo $row['user_email']; ?>" class="form-control" placeholder="" required>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control" placeholder="Enter New/Old Password" required>
<input type="hidden" name="user_id" value="<?php echo $row['user_id']; ?>">
</div>
<input type="submit" name="submitna" value="Update" class="btn btn-success">
</form>
<button data-dismiss="modal" class="btn btn-primary" type="button">Close</button>
Here is the php query that I wrote.
if(isset($_POST['submitna']))
{
$user_id=$_POST['user_id'];
$user_fullname = $_POST['user_fullname'];
$user_email = $_POST['user_email'];
$password = md5($_POST['password']);
$sql="UPDATE users SET user_fullname=?, user_email=?, password=? WHERE user_id=?";
$stmt=$conn->prepare($sql);
$stmt->bind_param("ssss", $user_fullname, $user_email, $password,$user_id);
if($stmt->execute()){
echo '<script>alert("Information has been updated")</script>';
header('location:index.php');
}
}
I've been stuck to this problem for two days and I can't fix it, so I decided to ask a question here. Hoping that you can help me. Thank you!
CodePudding user response:
Your user_id probably an Integer so the bind_param
should be
$stmt->bind_param("sssi", $user_fullname, $user_email, $password,$user_id);
CodePudding user response:
There is not a lot of info to go off of here, but I would recommend commenting out the header redirect so you can more easily debug your code:
echo '<script>alert("Information has been updated")</script>';
//header('location:index.php');
$stmt->debugDumpParams();