遇到鬼了,簡單的資料庫查詢,顯示Unknown column 'titletest' in 'field list'

來源:互聯網
上載者:User
資料欄位為:id(自增)、title(varchar(50)、content(longtext)
代碼為
$title = $_POST['title']; (值為:titletest)
$content =$_POST['content'];(值為:contenttest )
$insert = "insert into article(title,content) values(".$title.','.$content.")";

錯誤為:Unknown column 'titletest' in 'field list'

代碼為
$title = $_POST['title']; (值為:title test)這個和上面的多一個空格
$content =$_POST['content'];(值為:contenttest )
$insert = "insert into article(title,content) values(".$title.','.$content.")";

錯誤為:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'test,contenttest)' at line 1

將$insert = "insert into article(title,content) values(".$title.','.$content.")";
中的$title, $content 換成字串就可以插入


回複討論(解決方案)

語句有問題, 換成這樣 $insert = "insert into article(title,content) values('$title','$content')";

sql串得有問題,試試這個 $insert = "insert into article(title,content) values('".$title."','".$content."')";

$insert = "insert into article (title,content) values(‘$title','$content’)";

語句有問題, 換成這樣 $insert = "insert into article(title,content) values('$title','$content')";


謝謝,看來我還是太垃圾,這個簡單的問題搞了1個多小時,是不是變數本身需要一個引號呢?
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.