Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mySQL insert statement NOT working?

I've been looking around for an answer. I've been cross-referencing my code with others. And I don't seem to see any blatant errors...

My database does not update, my database does nothing. Oh and the page also does nothing too...... It's frustrating because, I'm just using notepad ++ and can't pinpoint the error. I'm using XAmpp as well, and, all the values match the ones I have made.

    The .post statement (Using jQuery 1.7.1):
    //Make sure DOM is loaded before running jQuery based code: [STATIC CODE]
$(document).ready(function(){

    $('#uploadbtn').click(function() {

        //Parse name and song.
        var name = $('#songname').val();
        var song =  $('#songupload').val();

        $.ajax(
        {
            type: 'POST',
            data: 'db/upload.php?name=' + name + 'song=' + song,
            success: function(res) {
                $('#nav-playlist').html(res);
            }
        }   
        )

    });

});



Now here is my php file:

<?php

/*Connection to database.
   First with mysql_connect (to log in). Then selecting the master database.
*/
echo "Upload.php accessed...";
$connection = mysql_connect("localhost", "root", "root") or die ( mysql_error() );
$database = mysql_select_db("betadb") or die( mysql_error() );

//Properties (to be inserted into database).
$name = mysql_real_escape_string($_POST["name"]); 
$song = mysql_real_escape_string($_POST["song"]);

//Insertion formula for mySQL
$query = "INSERT INTO songs SET name= '$name' song='$song' ";

if (mysql_query($query)){
echo "Success";
} 
else {

}

?>

ADDITIONAL NOTES: the song table consists of id, name, song (in that order). Song is the BLOB datatype, as it is used to store .mp3s

like image 503
CCates Avatar asked Feb 03 '26 12:02

CCates


1 Answers

The problem is with the following line

data    : 'db/upload.php?name='+name+'song='+song,

data should be an array containing the values, such as

var data
data["name"] = name
data["song"] = song

The $.ajax call is also missing the url parameter which is needed to carry out the request

url: 'db/upload.php'
like image 181
CBusBus Avatar answered Feb 06 '26 00:02

CBusBus