This doesn't work
$('#signup').submit(function(event) {
event.preventDefault();
var url = $(this).attr("action");
var data = $(this).serialize();
var callback = function(response) {$("#result").html(response);};
$.post(url, data, callback);
})
Try the below code in your form page with the JavaScript posted in your question:
<form id="signup" action="test_action.php">
<table width="300" cellpadding="3" cellspacing="0" border="0">
<tr><td>Name</td><td><input type="text" name="name" value="MY name" /></td></tr>
<tr><td>Email</td><td><input type="text" name="email" value="user@domain.com" /></td></tr>
<tr><td> </td><td><input type="submit" value="Post" /></td></tr>
<tr><td> </td><td id="result"> </td></tr>
</table>
</form>
Create a page 'test_action.php' with the below content for the form submit.
<?php
echo "success!";
?>
If you see the text 'success!' in the 'result' element, after the Post button click, the form submit works.
echo "Please fill in all of the fields!";
$errors = $emailrrors + 1;
}
$u_check = mysqli_query($mysqli,"SELECT un FROM users WHERE un='$un'");
$check = mysqli_num_rows($u_check);
if ($check===1)
{
echo "Username already taken ...";
$ok = 0;
$errors = 1;
}
$email_check = mysqli_query($mysqli,"SELECT email FROM users WHERE email='$email'");
$emailcheck = mysqli_num_rows($email_check);
if ($emailcheck===1)
{
echo "email already taken ...";
$ok = 0;
$errors = 1;
}
if($errors==0)
{
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
if($errors!=0)
{
echo 'something went wrong';
}