php - How do I update my database with mysqli and javascript -


i have website audioplayer , integrated lyricviewer on screen, user should able sync music hear playing. have 1 problem, , is; how on earth i, javascript function, call mysqli update statement? when user clicks save button, content gets thrown div, want php after javascript has been run take content , put database.

what best way that?

why doesn't work?

        function saveinphp() {         //alert("came here");         //var superstr = $( "#savelyric" ).text();         var superstr = 'lol';         $.ajax({         type: "post",         url: "includes/sendlyrics.php",         data: superstr,         cache: false,         contenttype: false,         processdata: false,         success:  function(data){             alert("---"+data);             alert("settings has been updated successfully." + data + "~~~" + superstr);             //window.location.reload(true);         }     });     } 

and php:

    <?php  include ('db_connect.php');  $data = $_post['data'];      $query = "update song set time=". $data ." id='1'";     mysqli_query($query); ?> 

write php in totally separate dedicated file takes post variables, constructs sql query, , inserts them database. have javascript function send data php file using post request.

javascript in browser cannot interact database. can send get/post requests server can catch requests , put attached data database.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -