資料庫的插入,該怎麼處理

來源:互聯網
上載者:User
資料庫的插入

$conn = mysql_connect("localhost","root","1234567");
mysql_query("SET NAMES 'utf8'");
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("code", $conn);

$sql="INSERT INTO keycode (key) VALUES ('$_POST[username]')";
if($_POST[username]!=null){
mysql_query($sql, $conn);
echo "status='$_POST[username]'";
}else
echo "no number!";
mysql_close();
?>

在flex端發送了一個參數過來,可為何插入不了的呢???
可以顯示 echo "status='$_POST[username]'"; 這個,可是資料庫裡就是沒看到有東西插入!!!!
各位高手,指點指點啊!!!!!


------解決方案--------------------
有可能是傳遞過來的中文無法正常插入。試下用英文能不能插入。如果可以的話 中文做一個iconv的轉碼.
------解決方案--------------------
mysql_query($sql, $conn) or die(mysql_error());//看看是否有錯

echo mysql_affected_rows($conn); //看看出入了幾條
------解決方案--------------------
這還不是錯嗎?
key 是 mysql 保留字,挪作他用時要轉義

$sql="INSERT INTO keycode (`key`) VALUES ('$_POST[username]')";
------解決方案--------------------
這種錯誤我以前也犯過啊
------解決方案--------------------
探討
都不行啊!!!好生鬱悶。
我把那個$sql 輸出來是這樣子的:INSERT INTO keycode (key) VALUES ('17')
然後我把它直接在mysql裡運行提示說:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server vers……
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.