<div class="display-flex" style="display: flex;">
<div class="from" style="margin-right: 200px;">
<input type="text" name="title" class="title"> <br>
<textarea name="content" class="content" id="" cols="30" rows="10"></textarea> <br>
<button type="button" class="button">Submit</button> <br>
</div>
</div>
<script>
$(document).ready(function(){
$('button').on('click', function(){
var titleValue = $('input.title').val();
var contentValue = $('textarea.content').val();
$.ajax({
method: "POST",
url: "some.php",
data: { title: titleValue, content: contentValue }
})
.done(function( ) {
});
$('input.title').val('');
$('textarea.content').val('');
})
});
</script>
<?php
require 'db.php';
$data = [
"title" => $_POST['title'],
"content" => $_POST['content']
];
$sql = 'INSERT INTO posts (title, content) VALUES (:title, :content)';
$stmt = $connect->prepare($sql);
$result = $stmt->execute($data);
var_dump($result);