ho trovato questo che sembra essere interessante per ciò che cerco...http://net.tutsplus.com/tutorials/ph...uery-and-json/
dove ho in html che sarebbe "il form"
Codice HTML:
<body>
<div id="comments">
<h2>Reader Comments</h2>
</div>
<div id="leaveComment">
<h2>Leave a Comment</h2>
<div class="row"><label>Your Name:</label><input type="text"></div>
<div class="row"><label>Comment:</label><textarea cols="10" rows="5"></textarea></div>
<button id="add">Add</button>
</div>
<script type="text/javascript" src="jquery-1.3.1.min.js"></script>
<script type="text/javascript">
$(function() {
//retrieve comments to display on page
$.getJSON("comments.php?jsoncallback=?", function(data) {
//loop through all items in the JSON array
for (var x = 0; x < data.length; x++) {
//create a container for each comment
var div = $("<div>").addClass("row").appendTo("#comments");
//add author name and comment to container
$("<label>").text(data[x].name).appendTo(div);
$("<div>").addClass("comment").text(data[x].comment).appendTo(div);
}
});
//add click handler for button
$("#add").click(function() {
//define ajax config object
var ajaxOpts = {
type: "post",
url: "addComment.php",
data: "&author=" + $("#leaveComment").find("input").val() + "&comment=" + $("#leaveComment").find("textarea").val(),
success: function(data) {
//create a container for the new comment
var div = $("<div>").addClass("row").appendTo("#comments");
//add author name and comment to container
$("<label>").text($("#leaveComment").find("input").val()).appendTo(div);
$("<div>").addClass("comment").text($("#leaveComment").find("textarea").val()).appendTo(div);
//empty inputs
$("#leaveComment").find("input").val("");
$("#leaveComment").find("textarea").val("");
}
};
$.ajax(ajaxOpts);
});
});
</script>
</body>
poi comment.php
Codice PHP:
<?php
//db connection detils
$host = "localhost";
$user = "root";
$password = "your_password_here";
$database = "comments";
//make connection
$server = mysql_connect($host, $user, $password);
$connection = mysql_select_db($database, $server);
//query the database
$query = mysql_query("SELECT * FROM comments");
//loop through and return results
for ($x = 0, $numrows = mysql_num_rows($query); $x < $numrows; $x++) {
$row = mysql_fetch_assoc($query);
$comments[$x] = array("name" => $row["name"], "comment" => $row["comment"]);
}
//echo JSON to page
$response = $_GET["jsoncallback"] . "(" . json_encode($comments) . ")";
echo $response;
?>
poi add comment.php
Codice PHP:
<?php
//db connection detils
$host = "localhost";
$user = "root";
$password = "your_password_here";
$database = "comments";
//make connection
$server = mysql_connect($host, $user, $password);
$connection = mysql_select_db($database, $server);
//get POST data
$name = mysql_real_escape_string($_POST["author"]);
$comment = mysql_real_escape_string($_POST["comment"]);
//add new comment to database
mysql_query("INSERT INTO comments VALUES(' $name ',' $comment ')");
?>
non ne so molto di php, il minimo ...
qui fa riferimento anche al database....dovrei associare un database al sito
siccome sto usando un host altervista gratuito li ci sarebbe un database...ma non saprei come associarlo o forse qui nei codici c'è già scritto ma lo vorrei essere spiegato...
grazie