In a data entry form, I would like that, when clicking on the 'Submit' button, it would not leave the page where the form is located.
When the forum is submitted, a popup is displayed with information to the user that the form was sent!
In a search, I know that AJAX exists, but I don't know how to implement it fully. I'm a PHP novice, I would like someone to help me with this!
Sorry my English!
HTML:
<form action="php/newsletter.php" method="post" class="formulario">
<input type="text" name="email" placeholder="Email" required>
</div>
<div class="ss-item-required" style="text-align:center;">
<button type="submit" class="site-btn">Send</button>
</div>
</form>
PHP:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "DB";
$conexao = new mysqli($servername, $username, $password, $dbname);
if ($conexao->connect_error) {
die("Erro na conexão: " . $conexao->connect_error);
}
if (!$conexao) {
die("Erro de ligação: " . mysqli_connect_error());
}
$sql = "INSERT INTO newsletter (email) VALUES ('email')";
if (mysqli_query($conexao, $sql)) {
echo '<div id="form-submit-alert">Submitted!</div>';
} else {
echo "Erro: " . $sql . "<br>" . mysqli_error($conexao);
}
?>