SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Apr 2014
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post jQuery with PHP

    Hello All,

    I have the following jQuery script that I would like to post to my mysql database with php. How would I go about getting this information to post to the database? Here is what I have so far.

    Thank you in advance.

    Code JavaScript:
    <script>
            $(document).ready(function () {
     
                //we want to intialze the values
                values = {};
                values['vehicle'] = "car";
                values['gender'] = "male";
                values['age'] = "25";
                values['position'] = "manager";
     
                //we need to handle the image clicks
                $("#car, #bus, #train, #boat, #plane, #man, #woman, #25, #35, #45, #55, #manager, #director, #president, #CXO").click(function (event) {
                    event.preventDefault();
     
                    //we want to know what row we are dealing with
                    var imageclass = $(this).attr('class');
     
                    //we need all of the other images in the row turned to not selected
                    $("." + imageclass).each(function() {
                        if ($(this).id != event.target.id)
                        {
                            var src = $(this).attr('src');
                            if (src.indexOf("2") >= 0)
                            {
                                $(this).attr('src', src.replace("2.png", ".png"));
                            }
                        }
                    });
     
                    setImageAsSelected(event.target.id);
                });
     
                function setImageAsSelected(id) {
                    var current = $("#" + id).attr('src');
                    var next;
                    if (current.indexOf("2") < 0) {
                        next = current.replace(".png", "2.png");
                    }
                    $("#" + id).attr('src', next);
                    values[$("#" + id).attr('class')] = id;
                }
     
                //we need to handle the go click
                $("#go").click(function () {
                    var sql = "INSERT INTO TABLE (Vehicle, Gender, Age, Positon) VALUES ('" + values['vehicle'] + "', '" + values['gender'] + "', '" + values['age'] + "','" + values['position'] + "');";
                    alert(sql);
                });
     
            });
     
        </script>
    Last edited by TechnoBear; Apr 26, 2014 at 05:43. Reason: Code tags added


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •