MySQL的insert语句不工作? [英] mySQL insert statement NOT working?

查看:158
本文介绍了MySQL的insert语句不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在四处寻找一个答案。我一直在交叉引用我的code与他人。而我似乎没有看到任何明显的错误...

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...

我的数据库没有更新,我的数据库什么都不做。哦,并且页面也确实没有什么太......这是令人沮丧,因为我只是用记事本+ +,不能查明错误。我使用的XAMPP,以及,所有的值相匹配的那些我已经做。

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 {

}

?>

其他注意事项: 歌曲表包括ID,姓名,歌曲(按顺序)。 宋是BLOB数据类型,因为它是用来存储.mp3s

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

推荐答案

现在的问题是使用以下行

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

在$就调用也缺少这是需要执行请求的URL参数

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

url: 'db/upload.php'

这篇关于MySQL的insert语句不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆