Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this:</p> <pre><code> $(document).on('click','#save',function(e) { var data = $("#form-search").serialize(); $.ajax({ data: data, type: "post", url: "insertmail.php", success: function(data){ alert("Data Save: " + data); } }); }); </code></pre> <p>and in <code>insertmail.php:</code></p> <pre><code>&lt;?php if(isset($_REQUEST)) { mysql_connect("localhost","root",""); mysql_select_db("eciticket_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."; } } ?&gt; </code></pre> <p>Don't use <code>mysql_</code> it's deprecated.</p> <p><code>another method:</code></p> <p>Actually if your problem is null value inserted into the database then try this and here no need of ajax. </p> <pre><code>&lt;?php if($_POST['email']!="") { mysql_connect("localhost","root",""); mysql_select_db("eciticket_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."; setcookie("msg","You have been successfully subscribed.",time()+5,"/"); header("location:yourphppage.php"); } if(!$sql) die(mysql_error()); mysql_close(); } ?&gt; &lt;?php if(isset($_COOKIE['msg'])){?&gt; &lt;span&gt;&lt;?php echo $_COOKIE['msg'];setcookie("msg","",time()-5,"/");?&gt;&lt;/span&gt; &lt;?php }?&gt; &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"/&gt; &lt;/form&gt; </code></pre>
 

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