PHP MySQL查询未插入 [英] PHP MySQL Query Doesn't Insert

查看:95
本文介绍了PHP MySQL查询未插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将查询插入数据库时​​遇到一些问题. 我有此php表单,该表单应执行插入查询,但没有任何反应,甚至没有错误.

I'm having some issues trying to insert a query into the database. I have this php form that should do an insert query but nothing happens, not even an error.

这是一个示例查询,格式为:

This is an example query with the form:

INSERT INTO FlashVideoList ('title', 'urltitle', 'description', 'tags', 'category', 'filename', 'filetype', 'size', 'uploadedbyuser', 'uploadtime') VALUES ('testtitle','testtitle','test','testtags','FlashVideo','SMILE!.swf','application/x-shockwave-flash','1007525','0','1339102426'); 

我回应了查询的内容以获取

i echoed the contents of the query to get this

这是php代码:

function MySqlQuery($Query)
{
    // Invokes global connection info
    global $MySQL_Host, $MySQL_Username, $MySQL_Password, $MySQL_Database, $MySQL_Port;
    global $mysqli;

    // runs query
    $result = $mysqli->query($Query);
    return $result;
}

$mysqli = new mysqli($MySQL_Host, $MySQL_Username, $MySQL_Password, $MySQL_Database, $MySQL_Port);

    MySqlQuery("INSERT INTO FlashVideoList ('title', 'urltitle', 'description', 'tags', 'category', 'filename', 'filetype', 'size', 'uploadedbyuser', 'uploadtime') " .
    "VALUES ('" . $mysqli->real_escape_string($_SESSION['Title']) . "','" . $mysqli->real_escape_string(GetUrlTitle()) . "','" . $mysqli->real_escape_string($_SESSION['Description']) . "','" .
    $mysqli->real_escape_string($_SESSION['Tags']) . "','" . $_SESSION['Category'] . "','" . $mysqli->real_escape_string($FlashFileName) . "','" . $mysqli->real_escape_string($_FILES["file"]["type"]) . "','" .
    $mysqli->real_escape_string($_FILES["file"]["size"]) . "','" . $mysqli->real_escape_string($UploadUserID) . "','" . time() . "');");

mysqli_free_result($result);
mysqli_close($mysqli);

感谢任何帮助,谢谢 选择查询与此代码相同就可以正常工作

Any help is appereciated, thanks Select queries work fine with this same code

好的,我已经取得了一些进展,似乎所有可能与此代码:P都是错误的,所以是的,现在这是我的查询:

Alright, i've made some progress, it seems that about everything possible is wrong with this code :P so yeah this is my query now:

INSERT INTO FlashVideoList (`title`, `urltitle`, `description`, `tags`, `category`, `filename`, `filetype`, `size`, `uploadedbyuser`, `uploadtime`) VALUES (`letitle`,`letitle`,``,`tagzz`,`FlashVideo`,`585336_pokemonsnewgrounds.swf`,`application/x-shockwave-flash`,`5058231`,`0`,`1339103842`); 

如果我直接通过navicat运行它,则会收到错误消息:

And if I run it directly through navicat i get the error:

[Err] 1054 - Unknown column 'letitle' in 'field list'

有人知道我在做什么错吗? :/

Anyone know what i'm doing wrong? :/

推荐答案

阅读错误消息.什么错误消息?好吧,这是另一个问题,但是它会说为什么插入失败 1 .

Read the error message. What error message? Well, that's another issue, but it would have said why the insert failed1.

注释中提到的一个(但不是唯一)问题是'不是有效的标识符引号,因此导致解析错误.在MySQL中,默认值为`,但是如果使用

One (but perhaps not the only) problem as mentioned in the comments is that ' is not a valid identifier quote and thus results in a parse error. In MySQL the default is `, but it can be changed (to ") if using ANSI quotes.

INSERT INTO FlashVideoList (`title`, ...)


1 此处是基本错误处理的示例用于mysqli(滚动到底部).基本思想是,如果query返回FALSE,则出现故障,可以/应该查阅error.


1 Here is an example of basic error handling for mysqli (scroll to the bottom). The basic idea is, if the query returns FALSE then something failed and error can/should be consulted.

此外,我建议清理代码并摆脱代理"函数调用.

Also, I'd recommend cleaning up the code and getting rid of the "proxy" function call.

这篇关于PHP MySQL查询未插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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