Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>jquery </p> <pre><code>$('form').submit(function(){ // check if passwords match; you might want to do more thorough validation var hasError = false; var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; var emailaddressVal = $("#email").val(); if(emailaddressVal == '') { $("#email").after('&lt;span class="error"&gt;Please enter your email address.&lt;/span&gt;'); hasError = true; } else if(!emailReg.test(emailaddressVal)) { $("#email").after('&lt;span class="error"&gt;Enter a valid email address.&lt;/span&gt;'); hasError = true; } else if(hasError == false) { // make ajax post request and store the response in "response" variable $.post('submit.php', $(this).serialize(), function(response){ // process response here (assume JSON object has boolean property "ok" if(response.ok=='0'){ alert('required fields empty'); }else if(response.ok=='1'){ alert('email already exists'); } else if(response.ok=='2') { alert('thankyou for your input'); } }, 'json'); } // stop the form from being submitted return false; }); </code></pre> <p>php code</p> <pre><code> &lt;?php ini_set('display_errors', 1); error_reporting(E_ALL); $con = mysql_connect("localhost","root",""); //Replace with your actual MySQL DB Username and Password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("table", $con); //Replace with your MySQL DB Name $first_name=mysql_real_escape_string($_POST['firstname']); $last_name=mysql_real_escape_string($_POST['lastname']); $email=mysql_real_escape_string($_POST['email']); if(empty($first_name) || empty($last_name) || empty($email) ) { echo json_encode( array('ok'=&gt; '0' ) ); exit(); } $sql="Select * from email_list where email='".$email."' "; $sqll=mysql_query($sql) or die($sql."&lt;br/&gt;&lt;br/&gt;".mysql_error()); $data=mysql_fetch_array($sqll); if($data['email']) { echo json_encode( array('ok'=&gt; '1' ) ); exit(); } $sql="INSERT INTO email_list (first_name,last_name,email) VALUES ('$first_name','$last_name','$email')"; mysql_query($sql) or die($sql."&lt;br/&gt;&lt;br/&gt;".mysql_error()); $value = mysql_insert_id() &gt; 0; if($value) echo json_encode( array('ok'=&gt; '2' ) ); mysql_close($con); exit(); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload