代码无法在没有错误的情况下向MySQL插入行

时间:2013-06-05 21:36:04

标签: php database error-handling

我将下面的代码作为我的查询(函数):

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();
    }
?>

1 个答案:

答案 0 :(得分:2)

您正在使用msql_*个函数,然后希望mysql_error能够正常运行。我猜这些msql_应该是mysql_