我是Codeigniter的新手。
事实是,表格不起作用。显示页面时没有错误;但我不知道为什么它不起作用。伙计们,请帮帮我。这是我的serarch_view.php
<html>
<head>
<title> `Insert Data Into Database Using CodeIgniter Form</title>
<link href='http://fonts.googleapis.com/css?family=Marcellus' rel='stylesheet' type='text/css'/>`
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ? >css/style.css" />
</head>
<body>
<div id="container">
<? echo form_open('insert_ctrl');?>
<h1>Insert Data Into Database Using CodeIgniter</h1><hr/>
<?php echo form_label('Search book according to :'); ?> <br />
<?php echo form_dropdown('dsearch',$options); ?><br />
<?php echo form_input(array('id' => 'dname', 'name' => 'dname')); ?><br />
<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?>
<?php echo form_close(); ?><br/>
</div>
</body>
这是我的观点insert_view.php
<html>
<head>
<title>Insert Data Into Database Using CodeIgniter Form</title>
<link href='http://fonts.googleapis.com/css?family=Marcellus' rel='stylesheet' type='text/css'/>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/style.css" />
</head>
<body>
<div id="container">
<? echo form_open('insert_ctrl/insert');?>
<h1>Insert Data </h1><hr/>
<?php if (isset($message)) { ?>
<CENTER><h3 style="color:green;">Data inserted successfully</h3></CENTER><br>
<?php } ?>
<?php echo form_label('isbn :'); ?> <?php echo form_error('disbn'); ?><br />
<?php echo form_input(array('id' => 'disbn', 'name' => 'disbn')); ?><br />
<?php echo form_label('Title :'); ?> <?php echo form_error('dtitle'); ?><br />
<?php echo form_input(array('id' => 'dtitle', 'name' => 'dtitle')); ?><br />
<?php echo form_label('Subject :'); ?> <?php echo form_error('dsubject'); ?><br />
<?php echo form_input(array('id' => 'dsubject', 'name' => 'dsubject')); ?><br />
<?php echo form_label('Category:'); ?> <?php echo form_error('dcategory'); ?><br />
<?php echo form_input(array('id' => 'dcategory', 'name' => 'dcategory')); ?><br />
<?php echo form_label('Author'); ?> <?php echo form_error('dauthor'); ?><br />
<?php echo form_input(array('id' => 'dauthor', 'name' => 'dauthor')); ?><br />
<?php echo form_label('Edition'); ?> <?php echo form_error('dedition'); ?><br />
<?php echo form_input(array('id' => 'dedition', 'name' => 'dedition')); ?><br />
<?php echo form_label('Publisher'); ?> <?php echo form_error('dpublisher'); ?><br />
<?php echo form_input(array('id' => 'dpublisher', 'name' => 'dpublisher')); ?><br />
<?php echo form_label('Copy :'); ?> <?php echo form_error('dcopy'); ?><br />
<?php echo form_input(array('id' => 'dcopy', 'name' => 'dcopy')); ?><br />
<?php echo form_label('Book Position:'); ?> <?php echo form_error('dbook_position'); ?><br />
<?php echo form_input(array('id' => 'dcbook_position', 'name' => 'dbook_position')); ?><br />
<?php echo form_label('Shelf Number :'); ?> <?php echo form_error('dshelf_number'); ?><br />
<?php echo form_input(array('id' => 'dshelf_number', 'name' => 'dshelf_number')); ?><br />
<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?>
<?php echo form_close(); ?><br/>
<div id="fugo">
</div>
</div>
</body>
这是我的控制器insert_ctrl.php
<?php
class Insert_ctrl extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->model('insert_model');
$this->load->helper('form');
//$this->load->view('insert_view');
}
function search() {
$data1['options']=array(
'titlewisesearch'=>'Title wise search',
'authorwisesearch'=>'Author wise search',
'isbnwisesearch'=>'ISBN wise search',
'subjectwisesearch'=>'Subject wise search',
);
$this->load->view('search_view',$data1);
//Setting values for tabel columns
$data['name'] = $this->input->post('dname');
$data['dsearch']=$this->input->post('dsearch');
$name=$data['name'];
$dsearch=$data['dsearch'];
//'return_date' => $this->input->post('dreturn_date'),
//'return_type' => $this->input->post('dreturn_type')
switch($dsearch)
{
case "titlewisesearch":$data['title_search']=$this->insert_model->search_title($name);
$title_search=$data['title_search'];
if(!empty($title_search))
{
foreach($title_search as $r)
{
echo $r;
}
}
else
echo "Enter the values";
break;
case "isbnwisesearch":$data['isbn_search']=$this->insert_model->search_isbn($name);
$isbn_search=$data['isbn_search'];
if(!empty($isbn_search))
{
foreach($isbn_search as $r)
{
echo $r;
}
}
else
echo "Enter the values";
break;
case "authorwisesearch":$data['author_search']=$this->insert_model->search_author($name);
$author_search=$data['author_search'];
if(!empty($author_search))
{
foreach($author_search as $r)
{
echo $r;
}
}
else
echo "Enter the values";
break;
case "subjectwisesearch":$data['subject_search']=$this->insert_model->search_subject($name);
$subject_search=$data['subject_search'];
if(!empty($subject_search))
{
foreach($subject_search as $r)
{
echo $r;
}
}
else
echo "Enter the values";
break;
}
//Transfering data to Model
}
function insert() {
//Including validation library
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('disbn', 'ISBN', 'required|min_length[5]|max_length[50]');
$this->form_validation->set_rules('dtitle', 'Title', 'required');
$this->form_validation->set_rules('dsubject', 'Subject', 'required');
$this->form_validation->set_rules('dcategory', 'Title', 'required');
$this->form_validation->set_rules('dauthor', 'Author', 'required');
$this->form_validation->set_rules('dedition', 'Edition', 'required');
$this->form_validation->set_rules('dpublisher', 'Publisher', 'required');
$this->form_validation->set_rules('dcopy', 'Copy', 'required');
$this->form_validation->set_rules('dbook_position', 'Book position', 'required');
$this->form_validation->set_rules('dshelf_number', 'Shelf number', 'required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('insert_view');
} else {
//Setting values for tabel columns
$data = array(
'isbn' => $this->input->post('disbn'),
'title' => $this->input->post('dtitle'),
'subject' => $this->input->post('dsubject'),
'category'=> $this->input->post('dcategory'),
'author' => $this->input->post('dauthor'),
'edition' => $this->input->post('dedition'),
'publisher' => $this->input->post('dpublisher'),
'copy' => $this->input->post('dcopy'),
'book_position' => $this->input->post('dbook_position'),
'shelf_number' => $this->input->post('dshelf_number')
);
//Transfering data to Model
$this->insert_model->form_insert($data);
$data['message'] = 'Data Inserted Successfully';
//Loading View
$this->load->view('insert_view', $data);
}
}
}
?>
这是我的insert_model.php
<?php
class insert_model extends CI_Model{
function __construct() {
parent::__construct();
$this->load->database();
}
}
function search_isbn($isbn){
$this->db->select('title');
$this->db->from('add_book');
$this->db->where('isbn', $isbn);
$query = $this->db->get();
if ( $query->num_rows() > 0 )
{
$row = $query->row_array();
return $row;
}
}
function search_author($author){
$this->db->select('title');
$this->db->from('add_book');
$this->db->where('author', $author);
$query = $this->db->get();
if ( $query->num_rows() > 0 )
{
$row = $query->row_array();
return $row;
}
}
function search_subject($subject){
$this->db->select('title');
$this->db->from('add_book');
$this->db->where('subject',$subject);
$query = $this->db->get();
if ( $query->num_rows() > 0 )
{
$row = $query->row_array();
return $row;
}
}
function form_insert($data){`//Inserting in Table(students) of Database(college)
$this->db->insert('add_book', $data);
}
}
?>
答案 0 :(得分:0)
将<? echo form_open('insert_ctrl');?>
替换为<?php echo form_open('insert_ctrl');?>
这可能是由于你的排序标签造成的。