Hi, in my UI ( image link above ) i have an update form with information from the database, when i edit something and click cancel button it will erase the edited information and display the original information from the database again. (javascript code below)
<script type="text/javascript">
function reset()
{
document.getElementById("1").innerHTML='<?php echo $data["Firstname"] ?>';
document.getElementById("2").innerHTML='<?php echo $data["Middlename"] ?>';
document.getElementById("3").innerHTML='<?php echo $data["Lastname"] ?>';
document.getElementById("4").innerHTML='<?php echo $data["Address"] ?>';
document.getElementById("5").innerHTML='<?php echo $data["PhoneNumber"] ?>';
document.getElementById("6").innerHTML='<?php echo $data["Birthdate"] ?>';
document.getElementById("7").innerHTML='<?php echo $data["Gender"] ?>';
}
</script>
Or if i click save button it will save the changes using ajax, it successfully updated my information in the database without reloading the page.
$(document).ready(function(){
//check if btnUpdate is clicked
$("#save").click(function()
{
var fname = $("#11").val();
var mname = $("#22").val();
var lname = $("#33").val();
var add = $("#44").val();
var phonenumber = $("#55").val();
var bdate = $("#66").val();
var gen = $("#77").val();
$.ajax(
{
url:"AdminBasicInfoUpdate.php",
type:"POST",
data:{"f":fname,"m":mname,"l":lname,"a":add, "p":phonenumber,"b":bdate,"g":gen },
success:function(e)
{console.log(e)
if(e == 1)
{
alert("No Changes Have Been Detected!");
}
else
{
$("#fullname").html(fname+ " " + lname);
alert("Personal Information Has Been Updated Success!");
$("#note").slideUp(500);
}
}
}
);
});
});
The Problem is after saving the changes when i click cancel button again it display the information before the update not the new updated information. Cant figure out how to fix it. i think i have to refresh the page in the background or update the sql query after clicking save butotn but i don't know how. I need help. Thanks in advance.
<php session_start();
include("connection.php");
$username=$_SESSION['Username'];
$sql = "SELECT * FROM table WHERE Username='$username'";
$res=mysqli_query($con,$sql);
$data=mysqli_fetch_assoc($res); ?>