how to get serialized array data in php?

Today, We want to share with you ajax serialize form data to php.In this post we will show you jquery serialize array for post, hear for how to get serialize form data in php we will give you demo and example for implement.In this post, we will learn about submit form using ajax javascript with an example.

How to Insert Data using serialize method PHP Ajax?

Table user_data

   CREATE TABLE `user_data` (
  `id` int(11) NOT NULL,
  `UserName` varchar(100) NOT NULL,
  `FullName` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

database.php

<?php
	$servername = "localhost";
	$username = "Aits_ams";
	$password = "DSF8754#$%^fcdf";
	$db="pakainfo";
	$conn = mysqli_connect($servername, $username, $password,$db);
?>

index.php

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script>
$(document).on('click','#update',function(e) {
    var data = $("#form-search").serialize();
    $.ajax({
         data: data,
         type: "post",
         url: "update.php",
         success: function(data){
              alert(data);
         }
	});
});
</script>
</head>
<body>
	<form action="" id="form-search">
	  User name: <input type="text" name="UserName" value="Rahul"><br>
	  Last name: <input type="text" name="FullName" value="Virat"><br>
	</form>
	<button id="update" name="update">Serialize form values</button>
</body>
</html>

update.php

<?php
	include 'database.php';
$UserName=$_POST['UserName'];
$FullName=$_POST['FullName'];
if(isset($_POST['update'])){
	$sql = "INSERT INTO `user_data`( `UserName`, `FullName`) 
	VALUES ('$UserName','$FullName')";
	if (mysqli_query($conn, $sql)) {
		echo "Good Luck, Succeess !";
	} 
	else {
	    echo "Sorry, Genrated Error !";
	}
	mysqli_close($conn);
}
?>

I hope you get an idea about serialize form data in js.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.