2013-06-05 43 views
-1

我有下面的代碼爲我的查詢(功能):代碼未能插入一行到MySQL沒有錯誤

function add_posts($title, $contents, $category_id){ 
    $posts_title = msql_real_escape_string($title); 
    $posts_content = msql_real_escape_string($contents); 
    $category_id = (int)$category_id; 
    $sql = "INSERT INTO `posts` (`posts_title`, `posts_content`, `category_id`) VALUES  ('$posts_title', '$posts_content', '$category_id')"; 
    $result = msql_query($sql)or die(mysql_error());} 

而一個在下一個隨後作爲我的HTML。當我運行它時,它不會插入數據,也不會顯示任何錯誤。

if (isset($_POST['posts_title'], $_POST['posts_content'], $_POST['category_id'])){ 
    $title = trim($_POST['posts_title']); 
    $contents = trim($_POST['posts_content']); 

    add_posts($title, $contents, $_POST['category_id']); 
    $Posts_id = mysql_insert_id(); 
    header('Location:Adminpage.php?posts_id ={$Posts_id}'); 
    die(); 
    } 
?> 
+0

你打開了[錯誤報告](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php)嗎?除非你安裝了非標準的庫,'msql_real_escape_string()'應該產生一個錯誤。 –

+0

查看你的代碼......什麼是'msql_'? –

回答

2

您使用msql_*功能,然後期待mysql_error工作。我猜想所有這些msql_應該是mysql_

+0

非常感謝你這是msql ...它現在的惰性再次感謝 – Kelvin