• Friday , 14 December 2018

Insert Data Into MySQL Database using jQuery + AJAX + PHP

Code Canyon



http://technotip.com/2208/insert-data-into-mysql-jquery-ajax-php/ Insert Data Into Database Without Refreshing Webpage.. Video tutorial illustrates insertion of …

Original source

3d Ocean

Related Posts

35 Comments

  1. I was born
    October 1, 2018 at 20:10

    So, who is shweta huh?

  2. Alexis Gacasan
    October 1, 2018 at 20:10

    what does this line do? "$("myForm").submit( function() {
    return false;
    });

  3. tictac Guys
    October 1, 2018 at 20:10

    $(document).ready(function(){
    $("#submit").click(function(e){
    var name = $("#name1").val();
    var np = $("#people1").val();
    var dt= $("#timenddate1").val();
    var msg = $("#msg1").val();

    if(name ==''|| np=='' || dt=='' || msg==''){
    alert("Some fields are blank");
    }
    else{

    // Returns successful data submission message when the entered information is stored in database.
    $.post("info.php",{
    name:name,
    Nopeople: np,
    DandT: dt,
    message: msg
    },
    function(data) {
    alert(data);
    $('#form2')[0].reset(); //To reset form fields after submission

    });

    e.preventDefault();
    }

    });

    });
    this code is working …but in the database empty values

  4. tictac Guys
    October 1, 2018 at 20:10

    thank you my friend ..but the first way is working with redirection …ajax is not working

  5. Sahil Vig
    October 1, 2018 at 20:10

    Thank you so much brother!

  6. Siva Anand
    October 1, 2018 at 20:10

    your way is very easy to understand …………

  7. Siva Anand
    October 1, 2018 at 20:10

    Thank you sir … . . . .

  8. Nsubili Mwaipopo
    October 1, 2018 at 20:10

    I fail on connecting

  9. Rakhi Singh
    October 1, 2018 at 20:10

    Thank u for this video ……….your way is very easy to understand …………

  10. Pentem
    October 1, 2018 at 20:10

    No matter what I try the page gets redirected

  11. Imran Rafique
    October 1, 2018 at 20:10

    this vedio is good one and gr8. Plz tell me email address need some help.

  12. uthej ks
    October 1, 2018 at 20:10

    Thanks a lot 🙂

  13. Jojo jaja
    October 1, 2018 at 20:10

    Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:xampphtdocssimpledb.php:2 Stack trace: #0 C:xampphtdocssimpleuserInfo.php(2): include_once() #1 {main} thrown in C:xampphtdocssimpledb.php on line 2

  14. Galaxy
    October 1, 2018 at 20:10

    Everything works. Thanks!.

  15. Matthew McFarland
    October 1, 2018 at 20:10

    nice video. It took a little while to get going, but really nice demonstration. Thanks for sharing. Matt, California.

  16. Dominik Gaida
    October 1, 2018 at 20:10

    thanks man, this helped a lot.
    hint for today (january 2018): output complains about: mysql_query is deprecated.
    I made some changes and it worked for me.
    the connection to db:
    $conn = new mysqli('localhost', 'root', 'your_pw', 'your_database');

    and the insert query:
    $conn->query("INSERT INTO table_name VALUES('whatever', 'values', 'you', 'got')");

  17. Magat Jonathan
    October 1, 2018 at 20:10

    Can i use this to make a chat system? I'm trying to make a chat without using interval to refresh a specific part of the page..

  18. Mubashar Hussain
    October 1, 2018 at 20:10

    thank thank thank and thank you solve my greate problem i dooo thissssssssssssssssssssssss

  19. mhouser1978
    October 1, 2018 at 20:10

    Don't know if anyone else will see this, seeing as this is the highest viewed content for the search terms "database" and "ajax". Decided to provide how I finally got this to work. I used XAMPP server and got this to work on Chome 61. This post helped me alot, https://stackoverflow.com/questions/16323360/submitting-html-form-using-jquery-ajax

    [***index.html***]
    <html>
    <head>
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script&gt;
    </head>
    <body>
    <form id="myForm" action="userInfo.php" method="post">
    <div>
    <label class="title">Name: </label>
    <input type="text" id="name" name="name" >
    </div>
    <div>
    <label class="title">Age: </label>
    <input type="text" id="age" name="age" >
    </div>
    <div>
    <input type="submit" id="sub" name="submitButton" value="Submit">
    </div>
    </form>

    <span id="result"></span>

    <script type='text/javascript'>
    /* attach a submit handler to the form */
    $("#myForm").submit(function(event) {

    /* stop form from submitting normally */
    event.preventDefault();

    /* get the action attribute from the <form action=""> element */
    var $form = $( this ),
    url = $form.attr( 'action' );

    /* Send the data using post with element id name and name2*/
    var posting = $.post( url, { name: $('#name').val(), age: $('#age').val() } );

    /* Alerts the results */
    posting.done(function( data ) {
    $("#result").html(data);
    });
    });
    </script>

    </body>
    </html>

    [***db.php***]
    <?php
    define('HOST','localhost');
    define('USERNAME', 'test');
    define('PASSWORD','test');
    define('DB','test');

    $con = mysqli_connect(HOST,USERNAME,PASSWORD,DB);
    ?>

    [***userInfo.php***]
    <?php
    include_once('db.php');

    $name = $_POST['name'];
    $age = $_POST['age'];

    $sql = "INSERT INTO user (FirstName, Age) VALUES ('".$name."', '".$age."')";

    if(mysqli_query($con, $sql))
    {
    echo "Record Saved";
    }
    else
    {
    echo "Error: ".mysqli_error($con);
    }
    mysqli_close($con);
    ?>

  20. Abu Bakr
    October 1, 2018 at 20:10

    Спасибо

  21. ManuAlvarado22
    October 1, 2018 at 20:10

    Thank you so much! This helped me a lot to understand .get/.post and .ajax.

  22. Vaibhav Srivastav
    October 1, 2018 at 20:10

    Hi Satish Sir,
    I have created a dynamic table by using JQuery and HTML now I want to fetch the data from each row of dynamic table but the dynamic table is created all row with the same name so How to fetch the value in php file?

  23. Amit Gupta
    October 1, 2018 at 20:10

    Are bhaiya isse achha hai ki tum hindi me hi video bana dete to kya ho jata …

  24. Ja Ja
    October 1, 2018 at 20:10

    Can you refresh it? (mysql_ = mysqli_) pls

  25. berrada mido
    October 1, 2018 at 20:10

    thks you bro for this video is simple , undestandeble and I invite you to come in morroco

  26. Programmer Arnab
    October 1, 2018 at 20:10

    lol… you forget to insert the action="" attribute elements and all of a sudden you php code corrected itself :p common.. you have to insert that second page name in action attribute in form tag

  27. Hazel Mae Damil
    October 1, 2018 at 20:10

    I did it exactly like you, but it still redirects once submit button is hit.

  28. Avg Karthik
    October 1, 2018 at 20:10

    ne yabba sariga explain chey work avadam ledu alert($("#myform").attr(''action"))); undefind vastundi

  29. Susmitha R
    October 1, 2018 at 20:10

    thanks bro

  30. javar ruedas
    October 1, 2018 at 20:10

    imba

  31. Fernanda Estrada
    October 1, 2018 at 20:10

    Thank you very much Satish. Excelent Tutorial

  32. pritam Saha
    October 1, 2018 at 20:10

    oh , u solved my problem. thank you .

  33. satlib wanzai
    October 1, 2018 at 20:10

    Thank you for your video. Please explain function(info). Why did you choose the name 'info'? Can we use any other name, or did you choose 'info' because it is a system global variable? Thanks:)

  34. Nakul Sarkar
    October 1, 2018 at 20:10

    i do exactly same……blank data stored in database……………….Why?

  35. Lucky c
    October 1, 2018 at 20:10

    learn php databa

Leave A Comment

You must be logged in to post a comment.