這裏是我的PHP:無法插入新行到數據庫
<?php
require included.php; //which contains the function getpost($post_id)
//once I use the getpost() function below to return a string which is the post
//content, then I can not insert this new row to database.if I change it something
//like $post_content='this is the post content' , it would insert a row to database
$post_content=getpost($post_id);
if($insert=mysql_query("INSERT INTO `join` VALUES('','username','$post_content')"))
{
echo 'ok';
}
else{
echo 'error';
}
?>
這裏是在included.php功能getpost($post_id)
:
function getpost($post_id){
$select_post=mysql_query("SELECT `post_text` FROM `user_post` WHERE `id`='$post_id' ");
return mysql_result($select_post,0,'post_text');
}
這些數據將被送回的jQuery AJAX作爲數據請求,如果我回應$post_content = get_post($post_id)
,我可以提醒正確的東西,使用函數來獲取發佈內容似乎是不對的,然後它不能被插入到數據庫中。
除去「VALUERS」中的「R」有一點。你爲什麼要命名一個表「加入」。這是一個SQL關鍵字,並會造成相當混亂的查詢。 –