Monday, 6 January 2014

Without webpage refreshing insert data into MySQL with jQuery

--------------------- my_form.php ------------------

<script src=""></script>

      $("#myForm").submit(function() {
            $.post("insert_data.php", $(this).serialize(),function(data){
       // data inserted "insert_data.php" 
            } )
            return false


        <form id="myForm" name="myForm" method="post" action="" >
<input type="text" id="name" name="name" />
<input type="text" id="message" name="message" />
<input id="submitbutton" type="submit" name="senddata" value="Submit Data" method="post">

<div id="info" > </div>


--------------------- insert_data.php ---------------------


mysql_connect("localhost", "root", "") or die(mysql_error());

echo "Connected to MySQL<br />";


        mysql_query("INSERT INTO tbl_mydata (name, message) VALUES('$name', '$message')");

         echo "Successfully Inserted";


No comments:

Post a Comment

Alternative content