I have a form and upon filling it out, I want the data to be inserted into a database. As of now, the database has two columns, "feedback" and "date". But right now, only the "date" gets inserted into the database, not the "feedback".
HTML Form:
<form class="form-inline" action="JavaScript:sendFeedback()" method="get">
<textarea name="Feedback" placeholder="Feedback..." rows="5" cols="100"></textarea>
<button type="submit" class="btn">Tell us</button>
</form>
Javascript:
function sendFeedback() {
_gaq.push(['_trackPageview', 'OutgoingLink=SendFeedback' ]);
$.get("../php/NewFeedback.php",{Feedback:$('input[name="Feedback"]').val()});
var element = document.getElementById("FeedbackArea");
element.innerHTML = "<div class=\"alert alert-success\"> <a class=\"close\" data-dismiss=\"alert\" href=\"#\">×</a>Thanks for your feedback!</div>";
return false;
}
php:
$db = MySql::getInstance(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
$Feedback = mysql_real_escape_string($_GET['Feedback']);
//create the sql statement
$sql = "INSERT INTO Feedback VALUES('{$Feedback}', CURDATE());";
//execute the query
$res = $db->query($sql);
And like I said, if I type something to the textarea and press the button "Tell us", the Database gets a new entry, but the "Feedback" attribute is empty (and the date is filled in).
Why is this?
$('textarea[name="Feedback"]').val()
– Arjun Abhynav Dec 29 '12 at 18:17