代码点火器插入到带有外部变量的 MySQL


codeigniter insert to mysql with external variable

我正在$post中发送我的表单,这意味着jquery帖子,到一个名为:register的文件.php

现在我的变量称为"名称"...所以在注册中.php这是我的代码:

<?php
include "external.php";
$CI->load->database();
$fullName=$_REQUEST['name'];
$data = array(
            'full_name' => $fullName
        );
$CI->db->insert('tbl_users', 'full_name'=>'');
if( $_REQUEST["name"] ) {
   $name = $_REQUEST['name'];
   echo "Welcome ". $name;
}
?>

外部.php是加载代码点火器。

请求名称是我想插入到数据库的内容...

代码正在向 db [full_name表] 插入一个空名称.. 我遇到了这个问题:

遇到 PHP 错误

严重性:警告

消息:mysql_real_escape_string() 期望参数 2 为 资源,给定布尔值

文件名: mysql/mysql_driver.php

行号:314

如何将$_REQUEST["name"]插入数据库?

 <?php echo form_open_multipart(base_url().'moderator/B2BCategory/insertname'); ?>
                    <div class="box-body">
                        <div class="row">
                            <div class="col-xs-6">
                                <div class="form-group">
                                    <label for="txtcatname">Title of Category :</label>
                                    <input type="text" name="txtname" class="form-control" id="txtname" placeholder="Category Name " required="required">
                                </div>
                            </div>

在控制器中

 public function insertname() {
        $this->load->helper(array('form', 'url'));
        $this->load->view('moderator/templates/header');
        $this->load->view('moderator/templates/sidebar');
         if ($this->input->post('selsub')) {
 $data = array('db_name' => $this->input->post('name'));
 $this->b2bcategory_model->form_insert($data);
            }
}

在模型中

public function form_insert($data){
$this->db->insert('jil_category', $data);
}

我相信这会帮助你