ahoj mam problem odesilam formular bez noveho nacitani vse funguje spravne pod formularem se mi ukaze co odeislam ale jakmile to ma php schroupat a poslat do db tak najednou nic
a script jquery
$(document).ready(function(){
$('button').click(function() {
$.post("comment.php",
{ name: $('#name').val(),
email: $('#email').val(),
text: $('#text').val()
}, function(data){
var html = '<ul>';
html += '<li><div id="posted_name">Autor: '+ $('#name').val() +'</div>';
html += '<div id="posted_text">'+ $('#text').val() +'</div></li>';
html += '<ul>';
$('.comments').append($(html));
}
);
return false;
});
});
formular
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Tvorba požadavku POST</title>
<link rel="stylesheet" href="styl.css" type="text/css" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/zpracuj.js" type="text/javascript"></script>
</head>
<body>
<div id="form_style" class="form">
<form id="form" name="form" method="post" action="comment.php">
<h1>Přidejte komentář</h1>
<label>Jméno<span class="small">Napište své jméno</span></label>
<input type="text" name="name" id="name" />
<label>Email<span class="small">Napište svůj e-mail</span></label>
<input type="text" name="email" id="email" />
<label>Text zprávy<span class="small">Napište svou zprávu</span></label>
<textarea name="text" rows="5" id="text"></textarea>
<button type="submit" name="submit">Komentovat</button>
</form>
</div>
<div class="comments"></div>
</body>
</html>
zpracujici script
<?php
include "./connect.php";
if (isset($_POST['submit'])) {
$nick = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$koment = mysql_real_escape_string($_POST['koment']);
if($nick==""){
echo 'neyl vyplněn nick';
}
else {
$sql = mysql_query("INSERT INTO koment VALUES('','$nick','$email','$koment')") or die (mysql_error());
echo'komentář byl úspěšně odesán';
}
}
?>