I've been struggeling with this problem for a while now and I still can't understand why it's not working. I've tried multiple possibilites but none of them worked, so can someone please help me with how to pass var superstr = $( "#savelyric" ).text();
through Ajax and into my database? This is what I've been experimenting with:
function saveinPHP() {
//alert("Came here");
var lyr = $( "#savelyric" ).text();
var superstr = { lyricsave:lyr }
//var superstr = 'lol';
//var hashString = "lol";
//var data = { yoururl:'hmm'}
$.ajax({
type: "POST",
url: "includes/sendlyrics.php",
data: superstr,
success: function(data){
alert("***DATA***"+data+"***MSG***");
alert("Settings has been updated successfully." + data + "~~~" + hashString);
//window.location.reload(true);
}
});
}
And as you can see, I've tried with multiple ways of doing it, but it just never works. I don't understand how on earth you do this. And the PHP file goes like this:
<?php
include ('db_connect.php');
$data = $_POST['data'];
$query = "UPDATE song SET time='".$data."' WHERE id='1'";
mysqli_query($query);
?>
And yes, I'm fully aware that my database is vulnerable for SQL injections, and I will fix that as soon as I get this working.
This is what I've tried, but I can do things completely different if you think that is necessary.
Right now I got the JS:
function saveinPHP() {
var superstr = $( "#savelyric" ).text();
$.ajax({
type: "POST",
url: "includes/sendlyrics.php",
data: {superstr: superstr},
success: function(data){
alert("***DATA***"+data+"***MSG***");
alert("Settings has been updated successfully." + data + "~~~");
//window.location.reload(true);
}
});
And PHP
<?php
include ('db_connect.php');
$data = $_POST['superstr'];
$query = "UPDATE song SET lyrtime='".$data."' WHERE id='1'";
mysqli_query($query);
?>