ajax скрипт + sql запрос
$("#send-post").on("click", function() {
var name = $('#name').val();
var email = $('#email').val();
var theme = $('#theme').val();
var msg = $('#msg').val();
$.ajax({
url: 'add-post.php',
type: 'POST',
data: {name:name, email:email, theme:theme, msg:msg},
error:function(){
$('#result').text("Ошибка!");
},
success: function(){
$('#result').text("Успешно!");
return 0;
}
});
});
include_once 'db_connect.php'; // проверяем подключение к базе данных
$name = $_POST['name'];
$email = $_POST['email'];
$theme = $_POST['theme'];
$msg = $_POST['msg'];
$result = mysql_query(" INSERT INTO `posts` (`name`, `email`, `theme`, `msg`) VALUES ('$name', '$email', '$theme', '$msg');");
Вывод из бд:<?php
$result = mysql_query("SELECT * FROM posts");
while($row = mysql_fetch_array($result)) { ?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['theme']; ?></td>
<td><?php echo $row['msg']; ?></td>
</tr><!-- Table Row -->
<?php } ?>