我正在使用codeigniter并尝试保存到MYSQL数据库表
我得到的错误是
Incorrect string value: '\xF0\x9F\x9A\x9A' for column 'post'
Run Code Online (Sandbox Code Playgroud) 我正在我的CodeIgniter项目中创建一个搜索页面.在提交时,表单调用控制器函数,通过模型函数获取数据,并将生成的数组传递给视图
问题是,当我刷新结果页面时,表单重新提交,因为$ _POST数据仍然存在于请求标头中.如何避免重新提交确认消息
以下是我的表单的代码:
<!--form-->
<form id="find" action="<?php echo base_url()?>search/find" method="post">
<input type="text" name="search_key" class="tb4" id="search_key" placeholder="Search here"/>
<input type="button" value="search"/>
</form>
Run Code Online (Sandbox Code Playgroud)
以下是我的控制器的代码:
/*
* function for fetching search results
* @param void
* @return void
*/
public function find()
{
$data['search_result']=$this->search_model->search($this->input->post('search_key'));
$this->load->view('template/header');
$this->load->view('pages/search_result',$data);
$this->load->view('template/footer');
}
Run Code Online (Sandbox Code Playgroud)
请帮助我.我不能使用重定向而不是加载视图,因为我必须将结果数组$ data传递给视图.
有没有办法在批量插入查询中执行,如果密钥已经存在,请在codeigniter中更新该行?我已经阅读了文档,发现只有insert_batch和update_batch.但是如何在活动记录中使用重复键更新行?如果在batch_insert中无法插入或更新一行,会发生什么?所有插入失败或只有那一行?
我创建了一个ENUM字段,这是我的代码:
$field['test'] = array(
'type' => 'ENUM',
'constraint' => array('a','b','c'),
'default'=> "a"
);
$this->dbforge->add_field($field);
$this->dbforge->create_table('demo');
Run Code Online (Sandbox Code Playgroud)
我收到一条消息:
错误号码:1064
您的SQL语法有错误; 检查与MySQL服务器版本对应的手册,以便在'Array'附近使用正确的语法DEFAULT'a'NOTE NULL)DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci'在第2行
CREATE TABLE
ci_demo(testENUM(Array)DEFAULT'a'NOT NULL)DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
请帮帮我,非常感谢你.
我知道如何在核心PHP中创建会话,我已经了解如何在codeigniter中执行此操作,但我无法理解如何检查,如果会话已设置?我试图通过View检查这个,但它总是给我meesage Please Login.
请告诉我如何检查会话是否设置
调节器
if ($user_type=='Student')
{
if ($LoginData= $this->loginmodel->studentLogin($username,$password))
{
foreach($LoginData as $UserId)
{
$currentId= $UserId->StudentId;
}
//[[session]]
$data['students_data']= $this->loginmodel->student_profile($currentId);
$this->session->userdata('$data');
$this->load->view('students',$data);
}
else
{
//$data['message']= array('Invalid Username or Password');
$this->load->view('Login');
echo "Invalid Username or Password";
}
}
elseif ($user_type=="Faculty")
{
if($data['faculty_data']=$this->loginmodel->faculty_admin($username, $password))
{
$this->session->userdata('$data');
$this->load->view('faculty');
}
else
{
$this->load->view('Login');
echo "Invalid Username or Password";
}
}
Run Code Online (Sandbox Code Playgroud)
视图
<?php
if (!$this->session->userdata('$data'))
{
echo "Please Login";
}
else
{
}
?>
<!DOCTYPE
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用account/verify_credentials和statuses/updateAPI.我总是收到错误202,请看下面返回的错误:
{"errors":[{"code":220,"message":"您的凭据不允许访问此资源."}]}
我正在开发一个类别模块,我正在使用CI验证规则.当验证规则失败时,我希望表单具有用户输入的相同值.我已经使用set_value函数在验证规则失败后加载表单中的值.但每次验证失败时,该值都将设置为空白.
这是我的代码.我在构造函数中设置了验证规则.
$this->form_validation->set_rules($this->validation_rules);
if ($this->input->post()) {
$db_array=array(
'CategoryName' => $this->input->post('CategoryName'),
'ParentID' => $this->input->post('ParentID'),
'Status' => $this->input->post('Status')
);
if($this->form_validation->run() != false){
if($id)
{
$result = $this->category_m->update($db_array,$id);
if(isset($result['error'])&& count($result['error']>0))
{
foreach($result['error'] as $error)
{
$this->session->set_flashdata('error',$error);
}
}
if($result['success'])
{
$action['class'] = 'success';
$action['msg'] = 'Data added successfully.';
$this->session->set_flashdata('success',$action);
}
else
{
$action['class'] = 'error';
$action['msg'] = 'Invalid values to the form!';
$this->session->set_flashdata('error',$action);
}
}
else
{
$result = $this->category_m->insert($db_array);
if(isset($result['error']) && count($result['error']>0))
{
foreach($result['error'] as $error)
{
$this->session->set_flashdata('error',$error);
}
}
if($result['success'])
{ …Run Code Online (Sandbox Code Playgroud) 在我的数据库中,它是一个表:tab_companies和一个company_phone(大整数)列,其中defalut值设置为NULL.
当有人填写表单并将电话号码字段留空时Code Igniter应该向数据库添加NULL值,但我总是将值设置为'0'.
public function add_company()
{
$data = array(
'company_short-name' => $this->input->post('company_short-name'),
'company_full-name' => $this->input->post('company_full-name'),
'company_phone' => $this->input->post('company_phone'),
'company_address' => $this->input->post('company_address'),
);
return $this->db->insert('tab_companies', $data);
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
我正在使用带有数据表的codeigniter,我想按列排序选择.
我怎样才能做到这一点 ?
$this->datatables->select('col_1, col_2, col_3');
$this->datatables->from('table');
....$this->datatables->order ?!?
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在使用PHP中的搜索系统,它将搜索到的文本添加到数组中,并使用json_encode()将其放入cookie中.
问题是:我需要检查cookie是否已经存在,如果没有,则创建它.
我正在使用以下代码来验证它是否存在但没有成功:
{
$search = $this->input->post('search_text');
$types = $this->input->post('search_type');
$checkboxes = "";
if(!empty($types))
{
foreach($types as $v)
$checkboxes = $v.",";
}
//cookie
$this->load->helper('cookie');
//cookie's array
$search_history = array();
array_push($search_history, $search);
//cookie check 1
if(get_cookie('search')!=''){
echo "cookie exists";
}else
echo "cookie doesn't exist";
// set cookie
$cookie = array(
'name' => 'search',
'value' => json_encode($search_history),
'expire' => time()+86500
);
set_cookie($cookie);
//cookie check 2
if(get_cookie('search')!=''){
echo "cookie exists";
}else
echo "cookie doesn't exist";
//echo get_cookie('search');
//redirect('search/'.urlencode($search).'/'.urlencode($checkboxes));
}
Run Code Online (Sandbox Code Playgroud)
我可以创建cookie并获得它的价值,但我似乎无法找到一种方法来检查它是否已经在PHP代码中创建.
已经尝试过:
if(get_cookie('search')!='')
Run Code Online (Sandbox Code Playgroud)
, …
codeigniter ×10
php ×7
mysql ×5
database ×2
forms ×2
bulkinsert ×1
cookies ×1
datatables ×1
dbforge ×1
emoji ×1
enums ×1
html ×1
pyrocms ×1
redirect ×1
session ×1
setvalue ×1
twitter ×1
unicode ×1
utf8mb4 ×1
validation ×1