如何使用codeigniter将表单值插入到mysql数据库 [英] How to Inserting Form values into mysql database using codeigniter

查看:177
本文介绍了如何使用codeigniter将表单值插入到mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的Codeigniter.How使用codeigniter在mysql中存储表单值,任何一个帮助我...有任何链接可以提供....
谢谢提前。 p>

I am new to the Codeigniter.How to store the form values in mysql using codeigniter ,Can any one help me...Is there any links Can you provide.... Thanks In Advance.

推荐答案

让我以简单的方式澄清你...

Let me clearify you in an easy way...

将是您的控制器

class Site extends CI_Controller
{
function index()
{
$this->load->view('form.php');// loading form view
}

function insert_to_db()
{
$this->load->model('site_model');
$this->site_model->insert_to_db();
$this->load->view('success');//loading success view
}
}

这将是你的意见。要创建视图,请转到autoload.php和自动加载url帮助程序和数据库类。
在你的config.php中设置config ['base_url'] =你的网站的路径;
form.php

This will be your views. Befor creating views go to autoload.php and autoload url helper and database class. In your config.php set config['base_url'] = "path to your site"; form.php

<form action="<?php echo base_url();?>index.php/site/insert_into_db" method="post">
Field 1 = <input type = 'text' name='f1'>
Field 2 = <input type = 'text' name='f2'>
Field 3 = <input type = 'text' name='f3'>
<input type='submit'>
</form>

success.php

success.php

<b>Your data has been inserted!!!</b>

在你的模型中,你需要拉这些形式的数据,并以这种方式插入db

In your model you need to pull those datas of form and insert into db this way

site_model.php

site_model.php

class Site_model extends CI_Model
{
function insert_into_db()
{
$f1 = $_POST['f1'];
$f2 = $_POST['f2'];
$f3 = $_POST['f3'];
$this->db->query("INSERT INTO tbl_name VALUES('$f1','$f2','$f3')");
}
}

在这种情况下,您的数据库有三个字段...根据您的要求修改查询

In this case your database has three fields... modify query as per your requirements

这篇关于如何使用codeigniter将表单值插入到mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆