0
Do you guys talk? I am beginner in development and I have a problem, I have a form (HTML) that sends data to a PHP file and registers in the database.
What I need is: When successfully recording the data, display on the "index" page (the one with the form) a custom alert in JQUERY (https://jqueryui.com/dialog/), I have tried several ways but could not. someone help me plzzz.
HTML:
<form action="cadastrar.php" method="post" class="form-inline" role="form">
<div class="form-group">
<label class="sr-only" for="email">Email address</label>
<input type="email" name="email" class="form-control" id="email" placeholder="Escreva o seu e-mail">
</div>
<button type="submit" class="btn btn-info">Cadastrar</button>
</form> </div>
php:
$sql = "INSERT INTO users (email)
VALUES ('$email')";
if ($conn->query($sql) === TRUE) {
$var = $var = "<script language= 'JavaScript'>
location.href='index.html'
</script>";
echo $var;
}
else {
echo "Esse email ja esta cadastrado";
}
$conn->close();
?>
PS: Abbreviated the code.
PS2: I know what I could do with ajax, but I have no idea how.
Thank you very much, a question that is even silly. This Jquery code I put in which part of the code? create a separate file? How will I "call" it in index after giving true in PHP?
– Lucas Rodrigues
in the HTML file you can include it within a <script> tag (jquery code here) </script> or create a separate file and import it into the script tag as well: <script src='arquivo_external.js'></script>.
– Ademilson Santana da Silva
As for the 'call it in index', note that the ajax code has a variable 'url' that is already directing to your php file. There in php Voce you have to make your logic of saving the email in the database, and when Voce gives an echo in PHP it will return this echo to your jquery code. (So only echo what is necessary)
– Ademilson Santana da Silva