I need to get the data that has been stored in my database to print in my website.I want to input the user entered word and then store it in a table after that i want it to show on a page.I have already saved created a form that takes the user entered data and stores it in a table but have not been able to display the data.I want the data entered by the user be available in any file
Here is my View
<form class="form-horizontal"
action="<?php echo base_url() ?>index.php/submit/new_form_submit" method="post">
<fieldset>
<br>
<div class="form-group">
<label class="col-md-4 control-label" for="Title">Title</label>
<div class="col-md-4">
<input id="Title" name="Title" type="text" placeholder="" class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="Price">Price</label>
<div class="col-md-4">
<input id="Price" name="Price" type="number" placeholder="" class="form-control input-md" required="">
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="textarea">Describe your product</label>
<div class="col-md-4">
<textarea class="form-control" id="textarea" name="textarea"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="Link">Link to Live preview</label>
<div class="col-md-4">
<input id="Link" name="Link" type="url" placeholder="e.g http://www.example.com" class="form-control input-md" required="">
</div>
</div>
<!-- File Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="filebutton">Screenshot of your theme</label>
<div class="col-md-4">
<label for="file-input">
<!-- <div class="thumbnail">
<img src="<?/*= base_url() */?>Images/placeholder.jpg"/>
</div>-->
</label>
<input id="file-input" type="file"/>
</div>
</div>
<br>
<!-- Button (Double) -->
<div class="form-group">
<label class="col-md-4 control-label" for="button1id"></label>
<div class="col-md-8">
<button type="submit" class="btn btn-success">Save</button>
<a id="cancel" name="cancel" class="btn btn-danger" href="<?php echo base_url(); ?>index.php/home">
Cancel</a>
</div>
</fieldset>
Here is my Controller
<?php
session_start();
class Submit extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('security');
$this->load->helper('url');
$this->load->helper('form');
$this->load->model('Submit_Database');
$this->load->library('form_validation');
}
public function index()
{
$this->load->view('templates/header');
$this->load->view('submitf/submit');
$this->load->view('templates/footer');
}
public function new_form_submit()
{
$this->load->helper('url');
$this->form_validation->set_rules('Title', 'Title', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE) {
$this->load->view('templates/header');
$this->load->view('pages/home');
$this->load->view('templates/footer');
} else {
$data = array(
'Title' => $this->input->post('Title'),
'Price' => $this->input->post('Price'),
'textarea' => $this->input->post('textarea'),
'Link' => $this->input->post('Link')
);
$result = $this->Submit_Database->submit_insert($data);
if ($result == TRUE) {
$this->load->view('templates/header');
$this->load->view('pages/about');
$this->load->view('templates/footer');
} else {
$this->load->view('templates/header');
$this->load->view('submitf/submit');
$this->load->view('templates/footer');
}
}
redirect('');
}
}
Here is my model
<?php
Class Submit_Database extends CI_Model
{
function __construct()
{
parent::__construct(); // construct the Model class
$this->load->database();
}
// Insert registration data in database
public function submit_insert($data)
{
// Query to insert data in database
$this->db->insert('submit', $data);
}
}
Any help would be much appreciated!
答案 0 :(得分:-1)
逻辑是这样的: 您需要模型中的函数才能从数据库中进行选择。 控制器中的一个函数,用于调用模型函数并使用数据加载视图。 以及一个实际显示数据的视图文件。 您可以使用会话将数据存储在会话变量中,并在任何文件中访问它。您必须加载会话库。