i think i have correctly writting this code but i get a problem on missing argument and i selected file image to upload but i get error too like this.
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Data_guru::edit()
Filename: tim_monitoring/Data_guru.php
Line Number: 90
Backtrace:
File: C:\xampp\htdocs\sdb\application\controllers\tim_monitoring\Data_guru.php
Line: 90
Function: _error_handler
File: C:\xampp\htdocs\sdb\index.php
Line: 315
Function: require_once
You did not select a file to upload.
thanks for your answer
My Controller
public function edit($id) {
$this->form_validation->set_rules('nama_guru','Nama Guru','required');
$this->form_validation->set_rules('alamat','Alamat','required');
if ($this->form_validation->run() === FALSE) {
$data = array ('title' => 'Edit Data Guru',
'detail' => $this->monitoring_model->detail_guru($id),
'isi' => 'monitoring/edit_guru_view'
);
$this->load->view('monitoring/layout/wrapper',$data);
//Kalau Tidak Ada Error Data Guru DiUpdate
}else{
$config['file_name'] = $this->input->post('nama_guru');
$config['upload_path'] = './assets/image/guru/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 3000;
$config['max_width'] = 3000;
$config['max_height'] = 3000;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('foto_guru'))
{
echo $this->upload->display_errors();
}
else
{
$gbr = $this->upload->data();
$data = array(
'foto_guru' => $gbr['file_name'],
'id_guru' => $this->input->post('id_guru'),
'nama_guru' => $this->input->post('nama_guru'),
'jenis_kelamin' => $this->input->post('jen_kel'),
'alamat' => $this->input->post('alamat'),
'tempat_lahir' => $this->input->post('tempat_lahir'),
'tgl_lahir' => $this->input->post('tgl_lahir'),
'no_hp' => $this->input->post('no_hp'),
'username' => $this->input->post('username'),
'password' => $this->input->post('password')
);
$this->monitoring_model->edit_guru($data);
redirect(base_url().'tim_monitoring/data_guru');
}
}
}
My Model
//Menampilkan Detail Guru Di Halaman Edit Guru
public function detail_guru($id) {
$query = $this->db->get_where('t_guru', array('id_guru' => $id));
return $query->row_array();
}
//Update Data Guru Setelah Di Edit Di Halaman Edt
public function edit_guru($data) {
$this->db->where('id_guru',$data['id_guru']);
return $this->db->update('t_guru',$data);
}
My View
<form action="<?php echo base_url() ?>/tim_monitoring/data_guru/edit" class="form-horizontal" method="post">
<div class="form-group">
<label for="inputEmail3" class="col-sm-4 control-label">Nama Guru</label>
<div class="col-sm-6">
<input type="text" name="nama_guru" class="form-control" placeholder="Nama Guru" value="<?php echo $detail['nama_guru'] ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-4 control-label">Tempat Lahir</label>
<div class="col-sm-6">
<input type="text" name="tempat_lahir" class="form-control" placeholder="Tempat Lahir" value="<?php echo $detail['tempat_lahir'] ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-4 control-label">Tanggal Lahir</label>
<div class="col-sm-6">
<input type="date" name="tgl_lahir" class="form-control" value="<?php echo $detail['tgl_lahir'] ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-4 control-label">Alamat</label>
<div class="col-sm-6">
<textarea name="alamat" class="form-control" rows="4" required><?php echo $detail['alamat'] ?></textarea>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-4 control-label">No Handphone</label>
<div class="col-sm-6">
<input type="number" name="no_hp" class="form-control" placeholder="No Handphone" value="<?php echo $detail['no_hp'] ?>" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Foto</label>
<div class="col-sm-6">
<input type="file" name="foto_guru" id="exampleInputFile" required>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-4 control-label">Username</label>
<div class="col-sm-6">
<input type="text" name="username" class="form-control" placeholder="Username" value="<?php echo $detail['username'] ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-4 control-label">Password</label>
<div class="col-sm-6">
<input type="password" name="password" class="form-control" placeholder="Password" value="<?php echo $detail['password'] ?>" required>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-4 control-label">Jenis Kelamin</label>
<div class="col-sm-6">
<input type="radio" name="jen_kel" value="L"><label> Laki - Laki</label>
<input type="radio" name="jen_kel" value="P"><label> Perempuan</label>
</div>
</div>
<input type="hidden" name="id_guru" class="form-control" value="<?php echo $detail['id_guru'] ?>" required>
<div class="form-group">
<div class="col-sm-4">
</div>
<div class="col-sm-6">
<button type="submit" class="btn btn-primary">Ubah Data</button>
</div>
</div>
</form>
Please see edit() Method of tim_monitoring/Data_guru.php that's must be require to pass one parameter as value of variable $id.
So, you need to add following URL in form's action
action="<?php echo base_url() ?>/tim_monitoring/data_guru/edit/<?php echo $detail['id_guru'] ?>"
For upload image form must require attribute enctype="multipart/form-data"
Related
i want to allow my user to update their profile and profile photo. if i comment the profile photo part in view and get rid in controller. the edit went well, but if i put the upload part in controller, the edit function not working. btw i'm still new in codeigniter. can you help me find my mistake.. thank you
my controller
public function edit($id){
$this->load->model('User_model');
$user = $this->User_model->getUser($id);
$data = array();
$data['user'] = $user;
$data1['user'] = $this->db->get_where('user', ['email' =>
$this->session->userdata('email')])->row_array();
$this->form_validation->set_rules('name', 'Name', 'required|trim');
$this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email');
$this->form_validation->set_rules('password1', 'Password', 'required|trim|min_length[8]|matches[password2]', [
'matches' => 'password not match!',
'min_length' => 'password too short'
]);
$this->form_validation->set_rules('password2', 'Password', 'required|trim|matches[password1]');
if ($this->form_validation->run() == false) {
$this->load->view('templates/admin/header', $data, $data1);
$this->load->view('templates/admin/sidebar', $data, $data1);
$this->load->view('templates/admin/topbar', $data1);
$this->load->view('admin/updateprofile', $data, $data1);
$this->load->view('templates/admin/footer', $data, $data1);
} else {
$upload_image = $_FILES['image']['name'];
if ($upload_image) {
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2048';
$config['upload_path'] = './assets/img/proile/';
$this->load->library('upload', $config);
if ($this->upload->do_upload('image')) {
$old_image = $data['user']['image'];
if ($old_image != 'default.jpg') {
unlink(FCPATH . 'assets/img/profile/' . $old_image);
}
$new_image = $this->upload->data('file_name');
$this->db->set('image', $new_image);
} else {
echo $this->upload->display_errors();
}
}
$data = array(
'name' => htmlspecialchars($this->input->post('name', true)),
'password' => password_hash($this->input->post('password1'), PASSWORD_DEFAULT),
);
$this->User_model->updateUser($id, $data);
$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">
User update successfully!
</div>');
redirect('adminprofile');
}
}
}
my model
function getUser($id)
{
$this->db->where('id', $id);
return $user = $this->db->get('user')->row_array();
}
function updateUser($id, $data)
{
$this->db->where('id', $id);
$this->db->update('user', $data);
}
my view
<div class="container-fluid">
<h1 class="h3 mb-4 text-gray-800">Edit Profile</h1>
<div class="row">
<div class="col-lg-8">
<form class="user" method="post" action="<?php echo base_url() . 'AdminUpdateProfile/edit/' . $user['id']; ?>">
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Nama</label>
<div class="col-sm-10">
<input type="name" class="form-control" id="name" name="name" value="<?= set_value('name', $user['name']); ?>">
</div>
</div>
<div class="form-group row">
<label for="email" class="col-sm-2 col-form-label">Emel</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" value="<?= set_value('email', $user['email']); ?>" readonly>
</div>
</div>
<div class="form-group row">
<label for="email" class="col-sm-2 col-form-label">Kata Laluan</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="password1" name="password1" placeholder="8 aksara">
<?= form_error('email', '<small class="text-danger pl-3">', '</small>'); ?>
</div>
</div>
<div class="form-group row">
<label for="email" class="col-sm-2 col-form-label">Ulang Kata Laluan</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="password2" name="password2" placeholder="Masukkan semula">
<?= form_error('email', '<small class="text-danger pl-3">', '</small>'); ?>
</div>
</div>
<div class="form-group row">
<div class="col-sm-2">Gambar Profil</div>
<div class="col-sm-10">
<div class="row">
<div class="col-sm-3">
<img src="<?= base_url('assets/img/profile/') . $user['image']; ?>" class="img-thumbnail">
</div>
<div class="col-sm-9">
<div class="custom-file">
<input type="file" class="custom-file-input" id="image" name="image">
<label class="custom-file-label" for="image">Choose file</label>
</div>
</div>
</div>
</div>
</div>
<div class="form-group row justify-content-end">
<div class="col-sm-10">
<button type="submit" class="btn btn-primary">Edit</button>
</div>
</div>
</form>
</div>
</div>
</div>
<!--<div class="container">
<div class="card o-hidden border-0 shadow-lg my-5 col-lg-7 mx-auto">
<div class="card-body p-0">
<div class="row">
<div class="col-lg">
<div class="p-5">
<div class="text-center">
<img src="<//?= base_url('assets/img/profile/') . $user['image']; ?>">
</div>
<hr>
<?= $this->session->set_flashdata('message'); ?>
<form class="user" method="post" action="<?php echo base_url() . 'AdminUpdateProfile/edit/' . $user['id']; ?>">
<div class="form-group row">
<input type="text" class="form-control" id="name" name="name" value="<?= set_value('name', $user['name']); ?>">
//<?= form_error('name', '<small class="text-danger pl-3">', '</small>'); ?>
</div>
<div class=" form-group row">
<input type="text" class="form-control" id="email" name="email" value="<?= set_value('email', $user['email']); ?>" readonly>
<?= form_error('email', '<small class="text-danger pl-3">', '</small>'); ?>
</div>
<div class="form-group row">
<input type="password" class="form-control" id="password1" name="password1" placeholder="Password">
<?= form_error('password1', '<small class="text-danger pl-3">', '</small>'); ?>
</div>
<div class="form-group row">
<input type="password" class="form-control" id="password2" name="password2" placeholder="Repeat Password">
</div>
<button type="submit" class="btn btn-primary btn-user btn-block">
Update
</button>
Cancel
</div>
</form>
</div>
</div>
</div>
</div> -->
First you have to use this after action attribute in form tag :
enctype='multipart/form-data'
You need to specify the enctype just like Aman said
<form class="user" method="post" action="<?= base_url('AdminUpdateProfile/edit/'.$user['id']); ?>" enctype="multipart/form-data">
your code here
</form>
As two of the above answers mention, first you need to add the encryption type to your form. So the end result would be:
<form method="post" enctype="multipart/form-data" class="user" action="<?php echo base_url() . 'AdminUpdateProfile/edit/' . $user['id']; ?>">
If this still doesn't work, in my case I had to convert the $_FILES indexes to $_FILES['userfile'] because of an issue with the upload library where it had issues with indexes that weren't userfile. I basically did this:
$this->load->library('upload');
$config['upload_path'] = 'images/';
$config['file_ext_tolower'] = TRUE;
$config['allowed_types'] = '*';
$this->upload->initialize($config);
$_FILES['userfile']['name'] = $_FILES['image']['name'];
$_FILES['userfile']['type'] = $_FILES['image']['type'];
$_FILES['userfile']['tmp_name'] = $_FILES['image']['tmp_name'];
$_FILES['userfile']['error'] = $_FILES['image']['error'];
$_FILES['userfile']['size'] = $_FILES['image']['size'];
$this->upload->do_upload();
$data = $this->upload->data();
This is my view page code
i check codeigniter form validation in codeigniter it's copy and paste my controller but same error
<form action="<?php echo base_url(); ?>admin/user_setup/store" method="post" class="ml-4 mr-4 mt-2" enctype="multipart/form-data">
<div class="row">
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="text" name="firstname" id="firstname" placeholder="নাম" class="form-control form__field" required>
<label for="firstname" class="form__label">নাম </label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="text" name="username" id="username" placeholder="ইউজার নাম" class="form-control form__field" required>
<label for="username" class="form__label">ইউজার নাম </label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="text" name="email" id="email" placeholder="ই-মেইল" class="form-control form__field" required>
<label for="email" class="form__label">ই-মেইল </label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<select name="activated" id="activated" class="form-control form__field" >
<option value="1">Active</option>
<option value="0">Inactive</option>
</select>
<label for="activated" class="form__label">অ্যাক্টিভেটেড</label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="password" name="password" id="password" placeholder="পাসওয়ার্ড" class="form-control form__field" required>
<label for="password" class="form__label">পাসওয়ার্ড</label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="password" name="confirm_password" id="confirm_password" placeholder="কন্ফার্ম পাসওয়ার্ড" class="form-control form__field" required>
<label for="confirm_password" class="form__label">কন্ফার্ম পাসওয়ার্ড</label>
</div>
</div>
<div class="col-lg-2 col-md-6 col-sm-12">
<div class="form-group form__group">
<label for="logo" class="form__label">ছবি </label>
<input type="file" name="logo" id="logo" placeholder="ছবি" class="form-control form__field" rows="2" cols="2" style="height: 38px;"></input>
</div>
</div>
<div class="col-lg-2 col-md-6 col-sm-12">
<div class="form-group form__group">
<select name="type" id="type" class="form-control form__field" >
<option value="2">এডিটর</option>
<option value="3">লাইসেন্স অফিসার</option>
</select>
<label for="type" class="form__label">ইউজার টাইপ</label>
</div>
</div>
<div class="col-lg-2 col-md-6 col-sm-12">
<div class="form-group">
<input type="submit" value="তৈরি করুন" class="form-control btn btn-sm btn-primary mt-fl">
</div>
</div>
</div>
</form>
this is my controller code
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[100]|alpha_dash');
$this->form_validation->set_rules('firstname', 'First Name', 'trim|required|xss_clean|min_length[6]|max_length[100]|alpha_dash');
$this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|minlength[6]|max_length[50]|alpha_dash');
$this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|xss_clean|matches[password]');
$data['errors'] = array();
echo $this->form_validation->set_value('username');
echo $this->input->post('username');
if ($this->form_validation->run()) {
$data['username'] = $this->form_validation->set_value('username');
$data['firstname'] = $this->form_validation->set_value('firstname');
$data['email'] = $this->form_validation->set_value('email');
$data['password'] = $this->form_validation->set_value('password');
$data['created'] = date('Y-m-d H:i:s');
$data['activated'] = $this->input->post('activated');
$data['type'] = $this->input->post('type');
$insert_id = $this->web_model->insert('users', $data);
var_dump("asduasiduiasdijasidij");
} else {
$errors = $this->tank_auth->get_error_message();
foreach ($errors as $k => $v) $data['errors'][$k] = $this->lang->line($v);
// $this->render_page('admin/setup/user_setup/create', $data);
echo $this->form_validation->run();
var_dump($data['errors']);
}
form validation don't return anything and $this->form_validation->set_value('any'); is always be empty
I load form_validation in controller __construct and also check load function inner but error is absolute
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
Check your PHPMyAdmin, I got the same problem last month, find xampp with build in PHP 5.6, link here https://sourceforge.net/projects/xampp/files/XAMPP%20Windows/5.6.40/ , delete or rename your old Windows(c:)/xammp/ and replace with PHP 5.6
I am working on codeigniter project in which viwe page having textboxes, radio buttons and button.I fetched textbox values from database and manually enter from date and to date then by clicking on save button insert query gets empty values because in controller i called all functions serially in index function.What is the best solution to call controller methods on each event of view page?
leave_appl_view.php
<form action="leave_apply_control/index" method="post" id="myForm">
<div class="row">
<div class="col-md-3">
<div class="form-group label-floating">
<label class="control-label">Emp ID</label>
<?php if(!empty($emp_leave))
{
foreach ($emp_leave as $liv)
{ ?>
<input type="text" class="form-control" name="id" value="<?php echo $liv->employee_id ?>" >
</div>
</div>
<div class="col-md-4">
<div class="form-group label-floating">
<label class="control-label">Employee Name</label>
<input type="text" class="form-control" name="empname" id="empname" value="<?php echo $liv->employee_name ?>" >
</div>
</div>
<div class="col-md-4">
<div class="form-group label-floating">
<label class="control-label">Email address</label>
<input type="email" class="form-control" name="empmail" id="empmail" value="<?php echo $liv->email ?>" >
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group label-floating">
<label class="control-label">Leave type: </label>
<input type="radio" id="half" name="type" onclick="Checkradiobutton()" value="half"> Half Day
<input type="radio" id="full" name="type" onclick="Checkbutton()" value="full" Checked> Full Day
</div>
</div>
<div class="col-md-3">
<div class="form-group label-floating" id="frm_dt">
<label class="control-label">From Date: </label>
<input type="text" class="form-control" id="datepicker1" name="from" ></p>
</div>
</div>
<div class="col-md-3">
<div class="form-group label-floating" id="to_dt">
<label class="control-label">To Date: </label>
<input type="text" class="form-control" id="datepicker2" name="to" ></p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group label-floating">
<label class="control-label">Balance Leaves</label>
<input type="text" class="form-control" name="bal_leave" value="<?php echo $liv->balanced_leaves ?>" >
</div>
<?php }
}
?>
</div>
<div class="col-md-3">
<div class="form-group label-floating">
<label class="control-label">Applied Leaves</label>
<input type="text" class="form-control" name="totaldays" id="totaldays" readonly>
</div>
</div>
<div class="col-md-3">
<div class="form-group label-floating">
<label class="control-label">Applied Date</label>
<input type="text" class="form-control" name="todayDate" id="todayDate" value="<?php echo date("d/m/Y"); ?>" readonly>
</div>
</div>
</div>
<div class="row">
<div class="col-md-7">
<div class="form-group label-floating">
<label class="control-label">Reason </label>
<TEXTAREA class="form-control" id="reason" name="reason"> </TEXTAREA>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary" id="submit" name="submit" onclick="<?php // echo base_url() ?>leave_apply_control/save_data">Apply</button>
<button type="reset" class="btn btn-primary" onclick="<?php echo base_url();?>leave_apply_control" >Reset</button>
</form>
leave_Apply_control.php
<?php
class leave_apply_control extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation'));
$this->load->library('calendar');
$this->load->database();
$this->load->model('user_model');
$this->load->helper('date');
}//contruct close
function index()
{
$id=$this->session->userdata('id');
$data['foren_id'] = $this -> user_model -> get_emp_id($id);
foreach($data['foren_id'] as $fk)
{
//echo "////control page fk is ".$fk->emp_id;
}
$data2['emp_leave'] = $this->user_model->get_leave_count($fk->emp_id);
$this->load->view('leave_application',$data2);
$this->save_data();
}
public function save_data()
{
$fd = date('Y-m-d',strtotime($this->input->post('from')));
$td = date('Y-m-d',strtotime($this->input->post('to')));
$data = array(
'employee_id' => $this->input->post('id'),
'emp_name' => $this->input->post('empname'),
'leave_from' => $fd,
'leave_to' => $td,
'no_of_days' => $this->input->post('totaldays'),
'applied_date' => date('Y-m-d H:i:s'),
'reason' => $this->input->post('reason'),
'mail' => $this->input->post('empmail'),
'leave_type' => $this->input->post('type'),
'balance_leaves' => $this->input->post('bal_leave'),
'status' => 1,
);
$this->user_model->insert_leave($data);
}
}
So I'm trying to insert in the database and upload a file. But when I'm trying to submit, it returns a server error.
The localhost page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500
I think the problem is in the $this->upload->do_upload('userfile') because i tried to comment out from this part and display echo the config array and there's no error but when i tried to uncomment up to this part, the error shows.
Controller
public function add_now(){
$this->load->library('form_validation');
$this->form_validation->set_rules('Event_Name', 'Event Name', 'trim|strip_tags');
$this->form_validation->set_rules('Event_Start', 'Start Date', 'trim|strip_tags');
$this->form_validation->set_rules('Event_End', 'End Date', 'trim|strip_tags');
$this->form_validation->set_rules('Event_Location', 'Location', 'trim|strip_tags');
if($this->form_validation->run() == FALSE){
$this->add();
}
else{
$query = $this->events_model->do_upload();
if($query){
$this->session->set_flashdata('success', 'Successful!');
$this->index();
}
else{
if(!$this->session->flashdata('upload_error')){
$this->session->set_flashdata('failed', 'Failed!');
}
$this->add();
}
}
}
Model
public function do_upload(){
$config['upload_path'] = './resources/images/events_photo/temp/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['file_name'] = uniqid().'.jpeg';
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
if(!$this->upload->do_upload('userfile')){
$this->session->set_flashdata('upload_error', $this->upload->display_errors());
}
}
View
<?php echo form_open_multipart('events/add_now'); ?>
<div class="panel-body">
<div class="row">
<div class="form-group">
<label class="control-label">Name</label>
<input type="text" class="form-control" name="Event_Name" value="<?php echo set_value('Event_Name'); ?>" placeholder="Enter Event Name">
<small class="text-danger"><?php echo form_error('Event_Name'); ?></small>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">Start Date</label>
<input type="text" class="form-control" name="Event_Start" value="<?php echo set_value('Event_Start'); ?>" placeholder="Enter Start Date" onclick="this.type='datetime-local'" onblur="this.type='text'" min="<?php echo date('Y-m-d'); ?>">
<small class="text-danger"><?php echo form_error('Event_Start'); ?></small>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">End Date</label>
<input type="text" class="form-control" name="Event_End" value="<?php echo set_value('Event_End'); ?>" placeholder="Enter End Date" onclick="this.type='datetime-local'" onblur="this.type='text'" min="<?php echo date('Y-m-d'); ?>">
<small class="text-danger"><?php echo form_error('Event_End'); ?></small>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-9">
<div class="form-group">
<label class="control-label">Location</label>
<input type="text" class="form-control" name="Event_Location" value="<?php echo set_value('Event_Location'); ?>" placeholder="Enter Event Location">
<small class="text-danger"><?php echo form_error('Event_Location'); ?></small>
</div>
</div>
</div>
<div class="row">
<textarea placeholder="Event Description" name="Event_Description" rows="10" class="form-control"></textarea>
</div>
<div class="row">
<div class="form-group">
<label class="control-label">Image Attachment (Optional)</label>
<input type="file" class="form-control" name="userfile" value="<?php echo set_value('userfile'); ?>" placeholder="Upload Image">
<?php if($this->session->flashdata('upload_error')): ?>
<small class="text-danger"><?php echo $this->session->flashdata('upload_error'); ?></small>
<?php endif; ?>
</div>
</div>
</div>
<div class="panel-footer text-right">
<button class="btn btn-success" type="submit">Submit</button>
</div>
</form>
First load the url helper in your controller...
$this->load->helper('url');
Then set the upload file path as:
$config['upload_path'] = base_url('resources/images/events_photo/temp/');
Try it might works.
And what about these two functions
$this->add();
$this->success();
I'm new to Codeigniter and I'm having problem with image upload function.
Error says - You did not select a file to upload.
Can anyone check my code and tell me what to do?
THIS IS MY CONTROLLER
This is my Controller which processes data.
public function add_data() {
$this->load->view('admin/header.php');
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'name', 'required');
$this->form_validation->set_rules('price', 'price', 'required');
$this->load->helper(array('form', 'url'));
if ($this->form_validation->run() == TRUE)
{
$this->load->view('admin/add_view.php');
$config['upload_path'] = './files/';
$config['allowed_types'] = 'jpg';
$this->load->library('upload', $config);
$this->upload->do_upload('picture');
$this->upload->data();
$data = array(
'name' => $this->input->post('name'),
'info' => $this->input->post('info'),
'gorod' => $this->input->post('gorod'),
'price' => $this->input->post('price'),
'amount' => $this->input->post('amount'),
'age' => $this->input->post('age'),
'status' => $this->input->post('status'),
'minbal' => $this->input->post('minbal'),
'contacts' => $this->input->post('contacts'),
'email' => $this->input->post('email'),
'alias' => $this->input->post('alias'),
'filename' => $this->input->post('picture')
);
$this->Adminmodel->add_record($data);
}
else
{
$this->load->view('admin/formnotsuccess');
}
}
VIEW
<form method="post" action="add_data" role="form" style="padding: 30px">
<div class="row">
<div class="form-group col-md-6 ">
<label>Название университета</label></br>
<input type="text" name="name" class="form-control" size="20">
</div>
</div>
<div class="row">
<div class="form-group col-md-10">
<label>Информация об университете</label></br>
<textarea id="textarea" name="info"></textarea>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Город</label></br>
<select class="form-control" id="gorod" name="gorod">
<option value="Алматы">Алматы</option>
<option value="Астана">Астана</option>
</select>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Стоимость обучения</label>
<input type="text" name="price" class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Количество студентов</label>
<input type="text" name="amount" class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Возраст университета</label>
<input type="text" name="age" class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Статус университета</label></br>
<select class="form-control" id="status" name="status">
<option value="Государственный">Государственный</option>
<option value="Частный">Частный</option>
</select>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Минимальный балл для поступления</label>
<input type="text" name="minbal" class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Контактные данные</label>
<textarea id="textarea2" name="contacts"></textarea>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>E-mail</label></br>
<input type="text" name="email" class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Alias</label></br>
<input type="text" name="alias" class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Картинка заднего фона</label></br>
<input type="file" name="picture" class="form-control">
</div>
</div>
<button type="submit" class="btn btn-default">Submit</button>
You are missing
enctype="multipart/form-data" in form
Read php file upload
And Upload code should be like bellow. Its easy to track your errors
if(!$this->upload->do_upload()) # do_upload('picture');
{
echo $this->upload->display_errors();
}
else
{
$data = $this->upload->data();
print_r($data);
}