-
Posts
197 -
Joined
-
Last visited
Moorcam's Achievements
-
Only SELECT queries have WHERE clauses mate.
-
Insert Automatically? I think you need to learn about php and MySQL etc. Here's a good place to start - https://www.phptutorial.net/php-pdo/php-pdo-insert/
-
What errors are you getting, if any? Also, use the code tags when posting to make it easier to read.
-
Redirect to installer if database is empty - Codeigniter 3
Moorcam replied to Moorcam's topic in Frameworks
Thank you -
Hi guys, If my application is not installed, and you go to the main website, it throws the following error: Message: Call to a member function first_row() on bool Now, this is obviously because the database is empty. What I would like to do, instead of showing this error, I would like to automatically redirect to the install directory (if it exists). In Model_common, the following function is what is throwing the error: public function all_setting() { $query = $this->db->query("SELECT * from tbl_settings WHERE id=1 ORDER BY id"); return $query->first_row('array'); } I have tried this but to no avail in Home.php controller under function index if (empty($data['setting'])) { redirect('../install/'); } If anyone could help with this I would appreciate it. Cheers Dan
-
500 Internal error when mod_rewrite enabled
Moorcam replied to Moorcam's topic in Apache HTTP Server
Never mind, Solved. mod_headers was disabled, causing a conflict in .htaccess. -
Hi guys, I have installed WAMP on my local machine. I have copied my project to the /www/ folder and when I open it in the browser, I get a 500 Internal Server Error. If I disable mod_rewrite the error goes away. Anyone got any idea? Nothing in error logs.
-
Hi again all, Posting this for anyone who has experienced similar. It appears Codeigniter 3 has a bug that does not check for file extensions. Thus, not allowing certain files to be uploaded. The workaround is to create a piece of code that will do the checking for us and allow for it to be uploaded. Here is that little piece of code: $ext = strtolower(pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION)); if ($ext != "csv") { // Not a CSV file - send error $this->session->set_flashdata('error', 'Incorrect file extension uploaded. Only .CSV allowed!'); redirect("admin/csv"); } Works a charm, thanks to my good friend Craig.
-
Hi guys, I want to be able to dynamically change a site's color scheme using JS Colorpicker. I have the JS amd form etc all set and the color is updating in the database. However, I need to be able to use that database entry to change a color hex in a xss file. I am using Codeigniter 3 Here is the HTML Form: <div class="tab-pane" id="color"> <?php echo form_open(base_url().'admin/setting/update',array('class' => 'form-horizontal')); ?> <div class="box box-info"> <div class="box-body"> <div class="form-group"> <label for="" class="col-sm-2 control-label">Color </label> <div class="col-sm-4"> <input type="text" name="footer_bg" class="form-control jscolor" value="<?php echo $setting['footer_bg']; ?>"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label"></label> <div class="col-sm-6"> <button type="submit" class="btn btn-success pull-left" name="form_color">Update</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> I have the following on the top of the style.php file: <?php header("Content-type: text/css"); ?> This all works fine if I say have the following: <?php header("Content-type: text/css"); $footer_bg = '#333'; ?> background-color: <?php echo $footer_bg; ?>; However, if I try to call the color from settings database table it won't work. Can anyone help with this? Cheers, Dan
-
Hi again folks, This really has me. I have changed to another method of importing, which includes uploading the file to the server and then reading it. Unfortunately, it isn't even uploading. Why? It baffles me as I have other uploads, such as images etc working just fine. Here is the controller now: function importcsv() { $data['fleet'] = $this->Model_fleet->show(); $data['error'] = ''; //initialize image upload error array to empty $config['upload_path'] = './uploads/csv/'; $config['allowed_types'] = 'csv'; $config['max_size'] = '1000'; $this->load->library('upload', $config); // If upload failed, display error if (!$this->upload->do_upload()) { $data['error'] = $this->upload->display_errors(); $this->load->view('admin/fleet', $data); } else { $file_data = $this->upload->data(); $file_path = $file_data['./uploads/csv/']; if ($this->Csvimport->get_array($file_path)) { $csv_array = $this->Csvimport->get_array($file_path); foreach ($csv_array as $row) { $insert_data = array( 'v_number'=>$row['v_number'], 'v_eng_number'=>$row['v_eng_number'], 'v_vin'=>$row['v_vin'], 'v_chassis'=>$row['v_chassis'], 'v_make'=>$row['v_make'], 'v_model'=>$row['v_model'], 'v_height'=>$row['v_height'], 'v_length'=>$row['v_length'], 'v_width'=>$row['v_width'], 'v_reg'=>$row['v_reg'], 'v_pax'=>$row['v_pax'], 'tacho_number'=>$row['tacho_number'], 'service_date'=>$row['service_date'], 'v_notes'=>$row['v_notes'], 'status'=>$row['status'], ); $this->Model_fleet->insert_csv($insert_data); } $this->session->set_flashdata('success', 'Csv Data Imported Succesfully'); redirect(base_url().'csv'); echo "<pre>"; print_r($insert_data); } else $data['error'] = "Error occured"; $this->load->view('admin/fleet', $data); } } Here is the Model: function insert_csv($data) { $this->db->insert('tbl_fleet', $data); } And the form (view): <!-- Modal Start --> <div class="modal fade" id="myModalDetail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog" style="width:900px;"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel"> Import Fleet </h4> </div> <div class="modal-body"> <div class="form-group"> <h3>Upload Fleet</h3> <h4>From the options below, you can simply import your fleet quickly by uploading a spreadsheet/</h4> <label for="exampleInputFile">Upload Excel or CSV</label> <?php echo form_open_multipart(base_url().'admin/fleet',array('class' => 'form-horizontal')); ?> <input type="file" name="file" ><br><br> <input type="submit" name="submit" value="UPLOAD" class="btn btn-primary"> <?php echo form_close(); ?> </div> </div> </div> </div> </div> <!-- Modal End --> I am also using the csvimport Library as below, which is saved in libraries/Csvimport.php <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter CSV Import Class * * This library will help import a CSV file into * an associative array. * * This library treats the first row of a CSV file * as a column header row. * * * @package CodeIgniter * @subpackage Libraries * @category Libraries * @author Brad Stinson */ class Csvimport { private $filepath = ""; private $handle = ""; private $column_headers = array(); /** * Function that parses a CSV file and returns results * as an array. * * @access public * @param filepath string Location of the CSV file * @param column_headers array Alternate values that will be used for array keys instead of first line of CSV * @param detect_line_endings boolean When true sets the php INI settings to allow script to detect line endings. Needed for CSV files created on Macs. * @return array */ public function get_array($filepath='', $column_headers='', $detect_line_endings=FALSE) { global $column_headers; // If true, auto detect row endings if($detect_line_endings){ ini_set("auto_detect_line_endings", TRUE); } // If file exists, set filepath if(file_exists($filepath)) { $this->_set_filepath($filepath); } else { return FALSE; } // If column headers provided, set them $this->_set_column_headers($column_headers); // Open the CSV for reading $this->_get_handle(); $row = 0; while (($data = fgetcsv($this->handle, 0, ",")) !== FALSE) { // If first row, parse for column_headers if($row == 0) { // If column_headers already provided, use them if($this->column_headers) { foreach ($this->column_headers as $key => $value) { $column_headers[$key] = trim($value); } } else // Parse first row for column_headers to use { foreach ($data as $key => $value) { $column_headers[$key] = trim($value); } } } else { $new_row = $row - 1; // needed so that the returned array starts at 0 instead of 1 foreach($column_headers as $key => $value) // assumes there are as many columns as their are title columns { $result[$new_row][$value] = trim($data[$key]); } } $row++; } $this->_close_csv(); return $result; } /** * Sets the filepath of a given CSV file * * @access private * @param filepath string Location of the CSV file * @return void */ private function _set_filepath($filepath) { $this->filepath = $filepath; } /** * Sets the alternate column headers that will be used when creating the array * * @access private * @param column_headers array Alternate column_headers that will be used instead of first line of CSV * @return void */ private function _set_column_headers($column_headers='') { if(is_array($column_headers) && !empty($column_headers)) { $this->column_headers = $column_headers; } } /** * Opens the CSV file for parsing * * @access private * @return void */ private function _get_handle() { $this->handle = fopen($this->filepath, "r"); } /** * Closes the CSV file when complete * * @access private * @return array */ private function _close_csv() { fclose($this->handle); } } If anyone can please provide any idea I would love you forever. There are no errors etc, just nothing happening. Cheers, Dan
-
Posted a few posts back, sorry. function saverecords($v_number,$v_eng_number,$v_vin,$v_chassis,$v_make,$v_model,$v_height,$v_length,$v_width,$v_reg,$v_pax,$tacho_number,$service_date,$v_notes,$status) { $this->db->insert('tbl_fleet',$v_number,$v_eng_number,$v_vin,$v_chassis,$v_make,$v_model,$v_height,$v_length,$v_width,$v_reg,$v_pax,$tacho_number,$service_date,$v_notes,$status); return $this->db->insert_id(); } Anyway, I have tried the following. It shows no result at all. public function import_data(){ if(isset($_POST['file'])) { $csv = $_FILES['file']['tmp_name']; $handle = fopen($csv,"r"); while (($row = fgetcsv($handle, 10000, ",")) != FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); } }
-
I have amended that in my last reply. I have tried other methods as well, uploading the file to /uploads/ and trying to read it from there. Can't even get the bloody thing to upload. I give up. Thanks anyway.
-
I am running this just after the success set_flashdata: echo "<pre>"; print_r($this->Model_fleet->saverecords); Nothing
-
Don't think so. I am already updating, adding, deleting data from that same Model. I have also modified the Model code for the saverecords so it is similar to others I am using: function saverecords($v_number,$v_eng_number,$v_vin,$v_chassis,$v_make,$v_model,$v_height,$v_length,$v_width,$v_reg,$v_pax,$tacho_number,$service_date,$v_notes,$status) { $this->db->insert('tbl_fleet',$v_number,$v_eng_number,$v_vin,$v_chassis,$v_make,$v_model,$v_height,$v_length,$v_width,$v_reg,$v_pax,$tacho_number,$service_date,$v_notes,$status); return $this->db->insert_id(); } My feeling is it is with the controller part posted below. I am just at a complete loss with it. public function importdata() { $this->load->view('view_fleet'); if(isset($_POST["submit"])) { $file = $_FILES['file']['tmp_name']; $handle = fopen($file, "r"); $c = 0;// while(($filesop = fgetcsv($handle, 1000, ",")) !== false) { $v_number = $filesop[0]; $v_eng_number = $filesop[1]; $v_vin = $filesop[2]; $v_chassis = $filesop[3]; $v_make = $filesop[4]; $v_model = $filesop[5]; $v_height = $filesop[6]; $v_length = $filesop[7]; $v_width = $filesop[8]; $v_reg = $filesop[9]; $v_pax = $filesop[10]; $tacho_number = $$filesop[11]; $service_date = $filesop[12]; $v_notes = $filesop[13]; $status = $filesop[14]; if($c<>0){ /* SKIP THE FIRST ROW */ $this->Model_fleet->saverecords( $v_number, $v_eng_number, $v_vin, $$v_chassis, $v_make, $v_model, $v_height, $v_length, $v_width, $v_reg, $v_pax, $tacho_number, $service_date, $v_notes, $status ); } $c = $c + 1; } echo "sucessfully import data !"; }else{ $this->session->set_flashdata('error',$error); redirect(base_url().'admin/fleet/edit/'.$id); } }
-
Same thing. I also sorted the 15 against the 2 variables (missed that) and also still the same.