textarea content created by ajax not inserted into database
i have a piece of code written in php
i use ajax to display a textarea when a certain button is clicked. it works fine and it's being displayed.
next to the textarea there is a submit button created also by the same button-click, which should insert the textarea content into a database table once it's set. but that doesn't seem to work
any help? thanks
there is the ajax code:
function answer(post)
{
var xmlhttp = null;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("answer").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","answer.php?p="+post,true);
xmlhttp.send();
}
and this is answer.php:
<?php
$p=$_GET['p'];
if (isset($_POST['_submit']) && $_POST['_text']!="") {
$answer=$_POST['_text'];
include 'db_connect.php';
mysql_query("INSERT INTO answer (p, answer) VALUES ('$p', '$answer')");
mysql_close($con);
}
else {
echo '<form method="post">';
echo '<texta开发者_如何转开发rea name="_text"></textarea>';
echo '<input type="submit" name="_submit" value="post"/><';
echo '</form>';
}
?>
Did you try setting the action attribute to the form?
精彩评论