Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Need Help Getting PHP/MySQL form processed via AJAX

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #32611
    Eamonn
    Member

    Hi Guys,
    The following code pieces are:

    • My opening Javascript snippet, forming the obj, in the header
    • The form, a dropdown, populated via PHP
    • The processing script, on tester-engine.php

    I am completely new to AJAX, and cannot see where this is falling down. Any help and explanations would be hugely appreciated.

    The header script:



    The Form:


    // db connection established


    Person info will be listed here.


    And, finally, the proccessing script:


    $q=$_GET["q"];

    // connection esablished

    $sql="SELECT * FROM contacts WHERE id = '".$q."'";

    $result = mysql_query($sql);

    echo "



    ";

    while($row = mysql_fetch_array($result))
    {
    echo "";
    echo "";
    echo "";
    echo "";
    }
    echo "
    Firstname Lastname
    " . $row . "" . $row . "
    ";

    Thanks in advance!

    #77168
    ChrisBull
    Member

    What’s wrong with it, Is is the request getting sent, is php not sending anything back, is the javascript function even getting called…?

    #77164
    Eamonn
    Member

    Well, it actually worked fine when the form options were hard coded as opposed to being auto populated via php. Now it doesn’t, and I just can’t figure why. I don’t know enough about AJAX to know if there’s an issue with php defined variables, and every example I can google seems to have hard coded values.

    To be clear – the form is being populated fine, but now, on selection, no response is being shown.

    #76955
    Eamonn
    Member

    Bump in hope….

    #76403
    smithbh
    Member

    This isn’t a solution, but may point you in the right direction.

    If you’re passing your values into a PHP array named “q” using GET, I’d recommend using the jQuery 1.5.0 .serialize() function to grab all the parameters from your form and passing them via the AJAX-inherent .get() function.

    Example:

    1) Add the following to your Header:




    2) Assign an ID to your form(this is my own personal preference as I favor using the jQuery ID selector):



    3) Not sure what event you’re using to submit the form – if using a submit button, add the following:



    Like I said, this isn’t a solution, but should help point you in the right direction. Also, I typically prefer to use the POST method as opposed to GET. To use this method instead, simply replace the above jQuery $.get(); function with $.post(); and replace $q=$_GET[“q”]; with $q=$_POST[“q”]; in your PHP.

    Hope this helps!

    Brandon


    http://www.vconstruct.com
    Build On The Cloud

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.