gpt4 book ai didi

php - codeigniter 仅以用户 1 身份插入数据

转载 作者:行者123 更新时间:2023-11-30 00:04:19 25 4
gpt4 key购买 nike

我正在尝试将一些数据插入 MySQL 数据库。但是它只接受用户 1 插入,这是数据库表中的第一个用户。我怎样才能让它插入所有用户,无论用户号是多少。

感谢您的宝贵时间。

这是我的插入代码

       <?php

class Mdl_chat extends CI_Model{

function Mdl_chat(){

parent::__construct();

}

function add_chat_message($chat_id, $user_id, $chat_text){
$query_str = "INSERT INTO chat_message (chat_id, user_id, chat_text) VALUES(?,?,?)";
$this->db->query($query_str, array($chat_id, $user_id, $chat_text));
}


function get_chat_messages($chat_id, $last_chat_message_id = 0){

$query_str = "SELECT
cm.chat_message_id,
cm.user_id,
cm.chat_text,
DATE_FORMAT(cm.created_at, '%D of %M %Y at %H:%i:%s')as chat_message_timestamp,
u.username,
u.profile_image_url
from chat_message cm
right join user as u on cm.user_id = u.user_id
WHERE cm.chat_id = ?
and cm.chat_message_id > ?
ORDER BY cm.chat_message_id asc";
$result = $this->db->query($query_str, array($chat_id, $last_chat_message_id));

return $result;

}



}


below is my user model which I am using to pass the user id that is in session to the sql
query in order to retrieve the right user against the chat message.

<?php

class Mdl_users extends CI_Model{



/*
*call to model class
*/

function __construct()
{
parent::__construct();
}


/*
*get userid from email column
*/
function get_userID($email){
$this->session->set_userdata('user');
$this->db->where('email',$email);
$query = $this->db->get('user')->row_array(); // retrieves row in session.

return $query['user_id'];

}


//get username
function get_username($email){
$this->db->where('email',$email);
$query = $this->db->get('user')->row_array(); // retrieves only first-row.
return $query['username'];
}

public function create_user()
{
$new_user_data = array(

'Email'=> $this->input->post('email'),
'Username'=> $this->input->post('username'),
'Password'=> $this->input->post('password'),
);

$insert = $this->db->insert('user',$new_users_data);
return $this->db->insert_id();

}


}

最佳答案

在你的数据库表中尝试将chat_id作为主键并检查自动增量选项打开

关于php - codeigniter 仅以用户 1 身份插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24722900/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com