> For the complete documentation index, see [llms.txt](https://javascriptuse.gitbook.io/advanced/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://javascriptuse.gitbook.io/advanced/serialize-width-php-mysql-ok.md).

# serialize width php mysql (ok)

![](/files/-MaC3vxosLTe9llijDzK)

![](/files/-MaC3zK12Gb6G5laQTmx)

C:\xampp\htdocs\windows\index.php

```
<!DOCTYPE html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
  <script type="text/javascript">
  $(document).on('click', '#save', function(e) {
  	e.preventDefault();
    var data = $("#form-search").serialize();
    $.ajax({
      data: data,
      type: "post",
      url: "save.php",
      dataType: 'json',
      success: function(data) {
        console.log(data)
      }
    });
  });
  </script>
</head>
<body>
  <form action="" id="form-search">
    First name: <input type="text" name="FirstName" value="Mickey"><br>
    Last name: <input type="text" name="LastName" value="Mouse"><br>
  </form>
  <button id="save">Serialize form values</button>
</body>
</html>
```

C:\xampp\htdocs\windows\save.php

```
<?php
include 'database.php';
$FirstName = $_POST['FirstName'];
$LastName  = $_POST['LastName'];
if (isset($_POST['FirstName'])) {
  $sql = "INSERT INTO `user_data`( `FirstName`, `LastName`) VALUES ('$FirstName','$LastName')";
  if (mysqli_query($conn, $sql)) {
    echo json_encode(["status"=>"Success!"]);
  } else {
    echo json_encode(["status"=>"Error!"]);
  }
  mysqli_close($conn);
}
?>
```

C:\xampp\htdocs\windows\database.php

```
<?php
	$servername = "localhost";
	$username   = "root";
	$password   = "";
	$db         = "school";
	$conn       = mysqli_connect($servername, $username, $password, $db);
?>
```

```
-- phpMyAdmin SQL Dump
-- version 5.1.0
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: May 21, 2021 at 06:01 AM
-- Server version: 10.4.18-MariaDB
-- PHP Version: 7.4.16

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `school`
--

-- --------------------------------------------------------

--
-- Table structure for table `user_data`
--

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

--
-- Dumping data for table `user_data`
--

INSERT INTO `user_data` (`id`, `FirstName`, `LastName`) VALUES
(0, 'Mickey', 'Mouse'),
(0, 'Mickey 1', 'Mouse 1'),
(0, 'Mickey 2', 'Mouse 2');
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

```

{% file src="/files/-MaC4hTHO57Avwap2VtS" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://javascriptuse.gitbook.io/advanced/serialize-width-php-mysql-ok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
