Note that there are some explanatory texts on larger screens.

plurals
  1. POError 500 after submitting the form in codeigniter
    primarykey
    data
    text
    <p>Using these MVC, I get Error 500. Any ideas?</p> <p><strong>Controller</strong> </p> <pre><code>&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Download extends CI_Controller { function __construct() { parent::__construct(); parent::__construct(); $this-&gt;load-&gt;library('form_validation'); $this-&gt;load-&gt;database(); $this-&gt;load-&gt;helper('form'); $this-&gt;load-&gt;helper('url'); $this-&gt;load-&gt;model('upload_model'); //$this-&gt;output-&gt;enable_profiler(TRUE); } function index() { $this-&gt;form_validation-&gt;set_rules('enter_product_name', 'Enter Product Name', 'required|max_length[200]'); $this-&gt;form_validation-&gt;set_rules('test_type', 'Test Type', 'required|max_length[200]'); $this-&gt;form_validation-&gt;set_rules('test_unit', 'Test Unit', 'required|max_length[200]'); $this-&gt;form_validation-&gt;set_rules('project_code', 'Project Code', 'required|max_length[200]'); $this-&gt;form_validation-&gt;set_error_delimiters('&lt;br /&gt;&lt;span class="error"&gt;', '&lt;/span&gt;'); if ($this-&gt;form_validation-&gt;run() == FALSE) // validation hasn't been passed { $data-&gt;page = 'download_form_view'; $this-&gt;load-&gt;view('container', $data); // $this-&gt;load-&gt;view('upload_form_view'); } else // passed validation proceed to post success logic { // build array for the model $file_name_info = $this-&gt;input-&gt;post('enter_product_name') .'_'. $this-&gt;input-&gt;post('test_type') .'_'. $this-&gt;input-&gt;post('test_unit') .'_'. $this-&gt;input-&gt;post('project_code'); $filename_data = array( 'download_name' =&gt; $file_name_info ); // run insert model to write data to db if ($this-&gt;download_model-&gt;DownloadName($filename_data) == TRUE) { //redirect('download/download'); $this-&gt;download(); } else { echo 'An error occurred while saving your filename to database. Please contact Admin with Issue No.[1]'; // Or whatever error handling is necessary } } } function download() { $this-&gt;load-&gt;helper('download'); $this-&gt;db-&gt;select('download_name'); $this-&gt;db-&gt;where("id", "0"); $this-&gt;db-&gt;limit(1); $query = $this-&gt;db-&gt;get('downloadname'); $download_save_name = $query-&gt;row()-&gt;download_name; $data = file_get_contents("./uploads/$download_save_name.xlsx"); force_download("$download_save_name.xlsx", $data); } } ?&gt; </code></pre> <p><strong>View</strong></p> <pre><code>&lt;?php // Change the css classes to suit your needs $attributes = array('class' =&gt; '', 'id' =&gt; ''); echo form_open('download', $attributes); ?&gt; &lt;p&gt; &lt;label for="enter_product_name"&gt;Enter Product Name &lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt; &lt;?php echo form_error('enter_product_name'); ?&gt; &lt;br /&gt;&lt;input id="enter_product_name" type="text" name="enter_product_name" value="&lt;?php echo set_value('enter_product_name'); ?&gt;" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="test_type"&gt;Test Type &lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt; &lt;?php echo form_error('test_type'); ?&gt; &lt;?php // Change the values in this array to populate your dropdown as required ?&gt; &lt;?php $options = array( '' =&gt; 'Please Select', 'LongTerm' =&gt; 'Long Term Study', 'ShortTerm' =&gt; 'Short Term Study', 'Experimental' =&gt; 'Experimental Study', ); ?&gt; &lt;br /&gt;&lt;?php echo form_dropdown('test_type', $options, set_value('test_type'))?&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="test_unit"&gt;Test Unit &lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt; &lt;?php echo form_error('test_unit'); ?&gt; &lt;?php // Change the values in this array to populate your dropdown as required ?&gt; &lt;?php $options = array( '' =&gt; 'Please Select', 'Hyd' =&gt; 'Hyd Unit', 'Viz1' =&gt; 'Viz Unit-1', 'Viz2' =&gt; 'Viz Unit-2', ); ?&gt; &lt;br /&gt;&lt;?php echo form_dropdown('test_unit', $options, set_value('test_unit'))?&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="project_code"&gt;Project Code &lt;span class="required"&gt;*&lt;/span&gt;&lt;/label&gt; &lt;?php echo form_error('project_code'); ?&gt; &lt;br /&gt;&lt;input id="project_code" type="text" name="project_code" value="&lt;?php echo set_value('project_code'); ?&gt;" /&gt; &lt;/p&gt; &lt;p&gt; &lt;?php echo form_submit( 'submit', 'Submit'); ?&gt; &lt;/p&gt; &lt;?php echo form_close(); ?&gt; </code></pre> <p><strong>Model</strong></p> <pre><code>&lt;?php class Download_model extends CI_Model { function __construct() { parent::__construct(); } function DownloadName($filename_data) { $this-&gt;db-&gt;update('downloadname', $filename_data, "id = 0"); if ($this-&gt;db-&gt;affected_rows() == '1') { return TRUE; } return FALSE; } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload