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.

Read Also:  JQuery AJAX form Submit and serialize send Server Side

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  vue Image Upload Component
  2. Read Also:  check if folder exists before create directory Laravel
  3. Read Also:  Remove null values from array in PHP
  4. Read Also:  PHP Laravel Join Query Example
  5. Read Also:  Display Image Preview Before Upload Multiple Images using jQuery,Ajax And PHP
  6. Read Also:  get value of radio button jquery
  7. Read Also:  Eloquent Order By Relation Column in Laravel
  8. Read Also:  javascript split string by comma
  9. Read Also:  Laravel 7 Custom Pagination View Example Tutorial
  10. Read Also:  PHP Highlight search matching text Results with Mysql
CLOSEX