为什么mysqli_insert_id不会递增?

时间:2014-05-08 16:39:19

标签: php

我正在尝试创建一个会话脚本。当有人填写我在另一页上的表格时。该值将插入此处。消息所针对的人的DB id(请记住,此脚本允许发送多条消息)。然后sendt消息应该放在DB中,每个$ conversation_id都不同,但是这里它没有增加,为什么?

function create_conversation($user_ids, $subject, $body)
{
    global $con;
    $subject = mysqli_real_escape_string($con, $subject);
    $body = mysqli_real_escape_string($con, $body);

    $sql = "INSERT INTO conversations VALUES('', '$subject')";
    $query = mysqli_query($con, $sql) or die(mysqli_error($con));

    $conversation_id = mysqli_insert_id($con);

    $sql = "INSERT INTO conversation_messages VALUES('', '$conversation_id', '{$_SESSION['user_id']}', NOW(), '$body')";
    $query = mysqli_query($con, $sql) or die(mysqli_error($con));

    $values = array();

    $user_ids[] = $_SESSION['user_id'];
    //print_r($user_ids);

    foreach($user_ids as $user_id)
    {
        $user_id = (int)$user_id;

        $values[] = "({$conversation_id}, {$user_id}, 0, '0')";
    }

    echo $sql = "INSERT INTO conversation_members VALUES " . implode(", ", $values);
    mysqli_query($con, $sql) or die(mysqli_error($con));
}

0 个答案:

没有答案