I have created a function using jQuery Ajax which create a new CSS element whenever I update the database using a form.
Is it ok? If not, hat can be the best method to do it?
$(document).ready(function(){
$('#statusupdater').submit(function(e) {
updatestatus();
e.preventDefault();
});
});
function updatestatus()
{
$.ajax({
type: "POST",
url: "statusupdate.php",
data: $('#statusupdater').serialize(),
dataType: "dataString"
});
$('#statuscontainer').prepend( $('<div id="stat">').load('statusupdate.php'));
$("#statusupdater")[0].reset();
$('.statuspop').fadeOut(300);
$('#opacify').hide();
}
statusupdate.php
<?php include "dbcon.php";
$status=$_POST['status'];
$photo=$_POST['photoupload'];
if ($status || $photo)
{
$date = date('m/d/Y h:i:s');
$statusinsert = mysqli_query($con,"INSERT INTO status (st_id,statu,date_created,userid) VALUES ('','$status','$date','$id')" );
}
$selectstatus = mysqli_query($con,"select * from status where userid = '".$id."' order by st_id desc limit 1");
$getstatus=mysqli_fetch_array($selectstatus);
?>
<div class="statbar"><?php echo $getstatus["userid"];?></div>
<div class="stattxt"><?php echo $getstatus["statu"];?></div>