• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Insert query problem

Participant ,
Mar 22, 2010 Mar 22, 2010

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;
    });
});

TOPICS
Server side applications

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 24, 2010 Mar 24, 2010

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

...

Votes

Translate

Translate
LEGEND ,
Mar 25, 2010 Mar 25, 2010

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 25, 2010 Mar 25, 2010

Copy link to clipboard

Copied

Hi,

I did this and it was working fine

It does not like it when submitting via ajax

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 26, 2010 Mar 26, 2010

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 />");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 29, 2010 Mar 29, 2010

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines