LUX
LUX

Reputation: 97

Jquery wont pass numbers to php

Everytime i try to submit my form it only returns "E" and only "E", i don't know why this is happening, can anyone help me with this issue?.

i've tried a number of ways and i can;t seem to get the result it should return

codes

Jquery:

        $('#edit_ok_btn').click(function(e)
{
    e.preventDefault();
    $('#NoticeBox').hide("slide", { direction: "up" }, 500, function() {
    $('#NoticeBox').show("slide", { direction: "up" }, 500);
    $('#NoticeBox').removeClass()
    $('#NoticeBox').addClass('Box_Working')
    $('#noticeText').html("Processing page...");

    var formData = $('#EditorForm').serialize();
    submitWebPage(formData);



    });
});

    function submitWebPage(formData) {

$.ajax({    
    type: 'POST',
    url: 'PageProcessor.php',       
    data : {'formdata' : formData},
    dataType: 'json',
    cache: false,
    timeout: 7000,
    success: function(data) {   


    $('#NoticeBox').hide("slide", { direction: "up" }, 500, function() {

        if(data.error == false)
        {
            $('#NoticeBox').show("slide", { direction: "up" }, 500);
            $('#NoticeBox').removeClass()
            $('#NoticeBox').addClass('Box_Success')
            $('#noticeText').html(data.msg);
            $('#PageEditor').fadeOut(1000);

            $('#NoticeBox').delay(1000).hide("slide", { direction: "up" }, 500, function() {
            location.reload();
            });



        }
        else
        {
            $('#NoticeBox').show("slide", { direction: "up" }, 500);
            $('#NoticeBox').removeClass()
            $('#NoticeBox').addClass('Box_Error')
            $('#noticeText').html(data.error);
        }

    }); 

    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {

    $('#responder').removeClass().addClass('Box_Error').html('<p>There was an ERROR!<strong></p>');


    }
});

PHP

$PageID         = $_POST['formdata']['EditID'];
$PageTitle      = $_POST['formdata']['PageTitle'];
$PageCategory   = $_POST['formdata']['CategoryList'];
$PageContent    = $_POST['formdata']['elm1'];
$PagePublished  = $_POST['formdata']['PublishPageOption'];

if($PageID == "NEW")
{

mysqli_query("INSERT INTO Web_Pages (Title, HTML, Category, Last_Author, Edit_Date, Published) VALUES ('".$PageTitle."','". $PageContent."','".$PageCategory."','LUX','".date("Y-m-d")."','".$PagePublished."') ");

        $return['error'] = false;
        $return['msg'] = '<i>'.$PageTitle.'</i> has been created successfully.'; 
        echo json_encode($return);
}
else
{
    mysqli_query("UPDATE Web_Pages SET Title = '".$PageTitle."', HTML = '".$PageContent."', Category = '".$PageCategory."', Last_Author='LUX', Edit_Date = '".date("Y-m-d")."', Published = '".$PagePublished."') WHERE ID = '".$PageID."' ");

        $return['error'] = false;
        $return['msg'] = '<i>'.$PageTitle.'</i> has been updated successfully.'; 
        echo json_encode($return);
}

paste-bin link to the source code

Upvotes: 1

Views: 101

Answers (2)

Hussein Nazzal
Hussein Nazzal

Reputation: 2557

im tired of this mistake !

 data: 'formData',

this will be now treated as string not a variable

i guess you should do something like this

data : {'formdata' : formData}

from php you can get the data with

$_POST['formdata'];

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324750

You have a ) near the end of the UPDATE query that shouldn't be there, most likely the result of a copy/paste/edit where you forgot the edit.

Upvotes: 2

Related Questions