我在这里有一个用户输入表单。这是它的代码!
<form id="addCommentForm" method="POST" action="#">
<div>
<input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>"/>
<label for="name">Your Name</label>
<input type="text" name="name" id="name" />
<label for="email">Your Email</label>
<input type="text" name="email" id="email" />
<label for="body">Comment Body</label>
<textarea name="bodytext" id="bodytext"></textarea>
<input type="submit" class="submit" value="Submit" />
</div>
</form>
但在提交时我收到此错误:
Notice: Undefined index: bodytext in /home/se212004/public_html/post-comment-mine.php on line 15
它指的是这段代码:
if (isset($_POST))
{
$username = $_POST['name'];
$email = $_POST['email'];
$content = $_POST['bodytext'];
$post_id=$_POST['post_id'];
$lowercase = strtolower($email);
$image = md5( $lowercase );
//insert these values into the db as a new comment
//example using array syntax to insert values
$statement = "INSERT INTO comments (name, body, dt, email) VALUES (?, ?, now(), ?)";
$sth = $db->prepare($statement);
$data = array($username, $content, $email);
$sth->execute($data);
}
错误指向 $content = $_POST['bodytext'];
. 任何解决此问题的帮助将不胜感激。
这是javascript文件。
$(function() {
$(".submit").click(function() {
var name = $("#name").val();
var email = $("#email").val();
var comment = $("#bodytext").val();
var post_id = $("#post_id").val();
var dataString = '&name='+ name + '&email=' + email + '&comment=' + comment + '&post_id=' + post_id;
if(name=='' || email=='' || comment=='')
{
alert('Please Give Valid JOE Details');
}
else
{
$("#flash").show();
$("#flash").fadeIn(400).html('<img src="ajax-loader.gif" align="absmiddle">& nbsp;<span class="loading">Loading Comment...</span>');
$.ajax({
type: "POST",
url: "post-comment-mine.php",
data: dataString,
cache: false,
success: function(html){
$("ol#update").append(html);
$("ol#update li:last").fadeIn("slow");
document.getElementById('email').value='';
document.getElementById('name').value='';
document.getElementById('comment').value='';
$("#name").focus();
$("#flash").hide();
}
});
}
return false;
});
});