0

I have a database of post office addresses. I have a page that will print the database in a table. I want to be able to update the address of the post office without reloading the whole page. I have a form to do this:

echo '<form id="AddressForm" method="post"><input type="hidden" name="form_PO" value="' . $row['PostOffice'] . '">Address: <input type ="text" name="submittedAddress"/><input name="submit" type="submit" value="Add"></form>';

(The form is in a while loop that prints the entire database, and an if statement that checks for an address and displays the form when address is empty)

I have an ajax script that I think is grabbing the POST data from the form and sending it to insert.php. My insert php works just fine as long as I manually set the post values. My problem is that it seems nothing is making it to insert.php.

Here's the ajax (blatantly stolen from another question):

    $(function () {

    $('form').on('submit', function (e) {
    e.preventDefault();
    $.ajax({
            type: 'post',
            url: 'insert.php',
            data: $('form').serialize(),
            success: function () {
               });
            });

)};

Here is how I'm trying to capture the post data in insert.php:

$selectedPO = $_POST['form_PO'];
$newAddress = $_POST['submittedAddress'];

I suspect I've made a rookie mistake in my ajax somewhere, but I've been unable to find it. Any details on how to debug such a thing would be useful.

Community
  • 1
  • 1
  • can you get anything from `print_r($_POST);` – Jacky Shek May 30 '16 at 03:06
  • have you used developer tools to see if there is a request firing at all? if it is, what is the output of the ajax request? – Tim Hysniu May 30 '16 at 03:16
  • @user2352577L Interesting, the print_r shows this: Array ( [form_PO] => ARARAT [submittedAddress] => Test Address [submit] => Add ) Which makes it look like the post is working. How can I tell what insert.php is actually getting? – Justin Deffenbaugh May 30 '16 at 04:19
  • maybe you need to try to put a full path in the `url` of ajax. if you can get the post in `insert.php`, you should see things of `print_r($selectedPO);` in `insert.php`. if it is nothing, may be some filters has occur in your enviroment such as xss filtering or waf. – Jacky Shek May 30 '16 at 04:25
  • insert.php is in the same directory as the ajax is. I'm not sure how to use print_r in insert.php since its never displayed anywhere. Where would that data be printed? – Justin Deffenbaugh May 31 '16 at 02:33

0 Answers0