Copy link to clipboard
Copied
I have a insert query that I have not changed, but for some reason it will not insert anything into the database.
The data gets inserted by a Ajax submit form and goes to insert.php
if(isset($_POST['message_wall'])){
/* Connection to Database */
include('config.php');
/* Remove HTML tag to prevent query injection */
$message = mysql_real_escape_string($_POST['message_wall']);
$to = mysql_real_escape_string($_POST['profile_to']);
$sql = 'INSERT INTO wall (message) VALUES(
"'.$message.'")';
mysql_query($sql);
I want to be able to add a user_id into the database too
The ajax code:
$(document).ready(function(){
$("form#submit_wall").submit(function() {
var message_wall = $('#message_wall').attr('value');
$.ajax({
type: "POST",
url: "insert.php",
data: "message_wall="+ message_wall,
success: function(){
$("ul#wall").prepend("<li style='display:none'>"+message_wall+"</li><br><hr>");
$("ul#wall li:first").fadeIn();
}
});
return false;
});
});
Hi
As this is an ajax form post then the data from the form should be inserted into your database using the insert.php script. Everything in the jQuery ajax form is passed to the processing script if you process it in the insert script it should work o/k.
You would then include a response text using a simple echo statement in your insert script, this should include anything you wish to be included on your page.
The php in your insert script would be similar to -
At top of script -
$date = $_POST["msg
...Copy link to clipboard
Copied
Hi Again
if I can findout how to send more than one value so that it can be inserted into the database.
This will be a problem with your php insert script or the database tables, not the ajax form. To check that the insert script is receiving all the form data I will repeat my previous recommendation to use a non-ajax form to submit the data to the ajax script for test purposes. Then echo each POST form item to the screen using the insert.php script.
PZ
Copy link to clipboard
Copied
Hi,
I did this and it was working fine
It does not like it when submitting via ajax
Copy link to clipboard
Copied
I think it is the insert.php
I can print from a hidden field into the ajax append
$("ul#wall").prepend("<li style='display:none'>"+message_wall+<br/>pro_to+"</li><hr />");
Copy link to clipboard
Copied
Hi just an update
I have fixed the insert issue.
$.ajax({
type: "POST",
url: "insert.php",
data: "message_wall="+ message_wall + "&pro_to="+ pro_to + "&msg_date="+ msg_date,
success: function(){
$("ul#wall").prepend("<li style='display:none'>"+message_wall+"</li><hr />");
thanks for all your help