Index.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("form#submit").submit(function() { $('div.blad').fadeIn(400); setTimeout(function(){ $("div.blad").fadeOut(400) }, 4000); return false; } $.ajax({ type: "POST", url: "insert.php", data: data, success: function(){ $('#mail').val(''); $('div.dodano').fadeIn(400); setTimeout(function(){ $("div.dodano").fadeOut(400) }, 4000); } }); return false; }); }); </script> </head> <body> <div id="content"> <form id="submit" method="post" name="submit" action=""> <label for="mail">mail:</label> <br /> <input type="text" name="mail" id="mail" class="text" size="20" /> <br /><br /> <button type="submit" id="submit"> Dodaj użytkownika </button> </form> <div class="dodano" style="display:none;"> <p><img class="tick" src="tick.png" alt="" />Użytkownik został dodany do bazy.</p> </div> <div class="blad" style="display:none;"> <p><img class="error" src="error.png" alt="" />Uzupełnij pola w formularzu!</p> </div> </div> </body> </html>
insert.php:
<?php //Odbieranie danych metodą post $baza_host=("localhost"); $baza_login=("x"); $baza_haslo=("x"); $baza_nazwa=("x"); $dodaj = "INSERT INTO aktualnosci (temat) VALUES ('$mail')"; ?>