私はCodeigniterを初めて使用します。codeigniterを使用してフォーム値をmysqlに保存する方法、誰かが私を助けてくれますか...リンクはありますか....よろしくお願いします。
47970 次
3 に答える
14
簡単な方法であなたを明確にしましょう...
これがあなたのコントローラーになります
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およびautoloadurlヘルパーとデータベースクラスに移動します。config.phpでconfig['base_url']="サイトへのパス";を設定します。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
<b>Your data has been inserted!!!</b>
モデルでは、これらのフォームのデータをプルして、この方法でデータベースに挿入する必要があります
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')");
}
}
この場合、データベースには3つのフィールドがあります...要件に応じてクエリを変更します
于 2012-05-09T11:44:27.423 に答える
1
CodeIgniterのマニュアルは非常に役立ちます。
データベースクイックスタートを見てください。
于 2012-05-09T11:23:53.243 に答える