Here's the code:
require("./connect.php"); function create_conversation($user_ids, $subject, $body) { $subject = mysql_real_escape_string(htmlentities($subject)); $body = mysql_real_escape_string(htmlentities($body)); mysql_query("INSERT INTO conversations (conversation_subject) VALUES ('{$subject}')"); $conversation_id = mysql_insert_id(); $sql = "INSERT INTO conversations_messages (conversation_id, user_id, message_date, message_text) VALUES ({$conversation_id}, {$_SESSION['id']}, UNIX_TIMESTAMP(), '{$body}')"; mysql_query($sql); $values = array(); $user_ids[] = $_SESSION['id']; foreach ($user_ids as $user_id) { $user_id = (int) $user_id; $values[] = "({$conversation_id}, {$user_id}, 0, 0)"; } $sql = "INSERT INTO conversations_members (conversation_id, user_id, conversation_last_view, conversation_deleted) VALUES " . implode(", ", $values); mysql_query($sql); } create_conversation(array_unique($user_ids), $_POST['subject'], $_POST['body']); mysql_close();Thanks .