簡體   English   中英

我似乎無法弄清楚為什么這個查詢給我錯誤

[英]I can't seem to figure out why this query gives me error

我在垃圾服務器上試圖為我的網站制作一個小的發布系統。

我要發布的PHP是:

$c=mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("postes");
$t = $_POST['title'];
$body = $_POST['body'];
$ts = time();
$query = mysql_query("INSERT INTO `postes`(`title`, `text`, `timestamp`) VALUES (`$t`,`$body`,`$ts`)")  or die(mysql_error());

然后,我使用Ajax發送:

$(document).ready(function () {
    $('#send').click(function () {
        var n = $('#title').val(),
            e = $('#body').val();
        $.post('post.php', {
            title: n,
            body: e
        }, function (data) {
            alert(data)
        });
    });
});

無論我在網站的標題字段中輸入什么,都會出現錯誤。 它說:“'字段列表'中的未知列'{text}'”

我什至沒有在sql的列部分中輸入標題,所以我不明白這一點。 另外,我是PHP和Mysql的新手

值必須用引號引起來,而不是反引號。 反引號用於表示數據庫,表,字段,索引等的名稱。

這個錯誤意味着此類字段不表存在postes

查詢

INSERT INTO `postes`(`title`, `text`, `timestamp`) VALUES (`$t`,`$body`,`$ts`)

要求您的postes表包含名為titletexttimestamp的列。 確保這些列存在於表定義中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM