Check if email already exists using jQuery and PHP
===

I am trying to validate the email address if it's already exist in the table but I can't get this to work.

I have the following code as a sample so you will understand what I mean:

	<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Untitled Document</title>
	<script src="http://code.jquery.com/jquery-latest.js"></script>
	<script type="text/javascript">
	$('#Submit').click(function() {
		var usernameVal = $('#email').val(); // assuming this is a input text field
		$.post('checkemail.php', {'email' : emailVal}, function(data) {
			alert('data');
		});
	});
	</script>
	</head>
	<body>
	<form id="form1" name="form1" method="post" action="view.php">
	  <p>
		<input type="text" name="email" id="email" />
	  </p>
	  <p>
		<input type="submit" name="Submit" id="Submit" value="Submit" />
	  </p>
	</form>
	</body>
	</html>

I want that when the Submit button is click, it should validate first using the jQuery and call the checkemail.php file as shown below:

	<?php
	include("../includes/db.php");
	
	$sql = "SELECT email FROM lf_clients WHERE email = " .$_POST['email'];
	$select = mysqli_query($con, $sql);
	$row = mysqli_fetch_assoc($select);
		
	if (mysqli_num_rows > 0) {
		echo "email already exists.";
	}
	?>

Whenever I click the submit button it goes directly to view.php. I want that before it redirect to view.php, it should check first if the email add already exist or not. If the email already exist then it should not redirect to view.php