Reputation: 7479
I am trying to insert some values into an sql database.
I am using
<input type="text" name="message" id="message" />
<input type="image" src="boca.png" onClick="send();" />
to get the value and
function send(){
var mess = $('#message').val('');
var dataString = 'message:'+ mess;
$.ajax({
type: "POST",
url: "atuamae.org/send.php",
data: dataString,
success: function() {
$('#message').val('');
}
}); }
to send it to the php file and in the php file:
$message = $_GET['message'];
I think the error occurs either in sending or in the way the var dataString is encoded
Upvotes: 2
Views: 342
Reputation: 9632
Simply enough, you're using the HTTP POST method, not the HTTP GET method, so you need to use $_POST
rather than $_GET
on the PHP side.
Upvotes: 3
Reputation: 1115
try:
var mess = document.getElementById('message').value;
var dataString = 'message='+ mess;
Upvotes: 1
Reputation: 2464
If you are using post you must use $_POST['message'] not $_GET['message']
Upvotes: 2
Reputation: 29991
You are setting the content of the '#message' element
Change
var mess = $('#message').val('');
to
var mess = $('#message').val();
And also, yes you are using POST
but trying to retreive the value through GET
Upvotes: 1