title: Insert data through ajax into mysql database
body: <p>Newsletter:</p>
  
  <pre><code>&lt;form id="form-search" method="post" action="&lt;?php echo $_SERVER['PHP_SELF'];?&gt;"&gt;
      &lt;span&gt;&lt;span class="style2"&gt;Enter you email here&lt;/span&gt;:&lt;/span&gt;
      &lt;input name="email" type="email" id="email" required/&gt;
  
   &lt;input type="submit" value="subscribe" class="submit" onclick="return fun()" /&gt;
                          &lt;/form&gt;
                          &lt;?php
  mysql_connect("localhost","","");
  mysql_select_db("");
  error_reporting(E_ALL &amp;&amp; ~E_NOTICE);
  
  $email=$_POST['email'];
  $sql="INSERT INTO newsletter_email(email) VALUES ('$email')";
  $result=mysql_query($sql);
  if($result){
  echo "You have been successfully subscribed.";
  }
   if(!$sql)
  die(mysql_error());
  
  mysql_close();
  
  ?&gt;
  </code></pre>
  
  <p>But I want to insert my E-Mail to database through Ajax. I don't want my page to get redirected, because every time the page got refreshed, null value got inserted to the database.. </p>
  
  <p>I just want my E-mail got inserted to database through Ajax, and after that the email box
  i.e.</p>
  
  <pre><code>&lt;input name="email" type="email" id="email" required/&gt;  
  &lt;input type="submit" value="subscribe" class="submit" onclick="return fun()" /&gt;
  </code></pre>
  
  <p>should get disappeared and there should be the line "you've been successfully subscribed" .. </p>
  
  <p>Any brief code will be very useful.. thank u in advance :)</p>