I am trying to upload image to the folder on the server and store another data in the databse from the same form simultaneously. But it is showing error You did not select a file to upload.
Below is my view and controller for the same:
View:
<form role="form" method="post" action="job_insert" enctype="multipart/form-data">
<div class="box-body">
<div class="form-group">
<label>Job Name*</label>
<input type="text" class="form-control" name="jname" placeholder="Enter Job Name" required>
</div>
<div class="form-group">
<label>Description</label>
<textarea rows="4" cols="10" class="form-control" name="description" required></textarea>
</div>
<div class="form-group">
<label>File input</label>
<input type="file" name="userimage">
</div>
<div class="form-group">
<label>Paper Size*</label>
<div class="form-group">
<label>Paper Cutting Size</label>
<div>
<input id="cutting_size" name="cutting_size" type="text" placeholder="Cutting Size" class="form-control input-md" required>
</div>
</div>
<div class="form-group">
<label>Sheet</label>
<div>
<input id="sheet" name="sheet" type="text" placeholder="No. of Sheet" class="form-control input-md" required>
</div>
</div>
<div class="form-group">
<label>Tin No.</label>
<div>
<input id="sheet" name="tin" type="text" placeholder="Tin No." class="form-control input-md" required>
</div>
</div>
</div>
<!-- /.box-body -->
<div style="margin-left: 600px" class="box-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
Controller:
public function job_insert()
{
$this->form_validation->set_rules('jname', 'job_name', 'trim');
if($this->form_validation->run()== FALSE)
{
$this->load->view('invalid_jobname');
}
else
{
$this->do_upload();
$data = $_SESSION['email'];
$id = $this->user_model->get_client_id($data);
$data = array('cid' => $id,
'job_name' => $this->input->post("jname"),
'job_id' => $this->input->post("job_id"),
'description' => $this->input->post("description"),
'img_name' => $img_name,
'adate' => Date('Y-m-d'),
'status' => 'NEW',
'paper_size' => $this->input->post("paper_size"),
'paper_type' => $this->input->post("paper_type"),
'cutting_size'=> $this->input->post("cutting_size"),
'sheet'=> $this->input->post("sheet"),
'tin' => $this->input->post("tin"),
'lamination' => $this->input->post("checkboxes"),
'print_type' => $this->input->post("checkboxes1"),
'binding' => $this->input->post("checkboxes2"),
);
$query = $this->user_model->job_insert($data);
if ($query == TRUE)
{
$this->load->view('job_submitted');
}
else
{
$this->load->view('error_page');
}
}
}
Here's my do_upload function:
public function do_upload()
{
$config = array(
'upload_path' => "./uploads/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => FALSE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
$image = $this->input->post("image");
echo $image;
if(!$this->upload->do_upload('userimage'))
{
$error = $this->upload->display_errors();
echo $error;
}
}
Change this to
<input type="file" name="image">
to
<input type="file" name="userfile"/>
and in do_upload
if(!$this->upload->do_upload())
to
if ( ! $this->upload->do_upload('userfile'))
Provide enctype="multipart/form-data" in your form tag. Without it you cannot upload image.
update form tag with below code
<form role="form" method="post" action="job_insert" enctype="multipart/form-data">
Related
I have a problem when I add multiple images, they are saved in a file instead of the image being saved ...
Look
https://gyazo.com/de126b998c2967f421805e933b53b30b
My Function
public function createPage(Request $request)
{
$images = $request->input('images');
$pages = Pages::create([
'title' => $request->input('title'),
'meta_title' => $request->input('meta_title'),
'content' => $request->input('content')
]);
// Store each Images
foreach ($images as $image) {
$imagePath = Storage::disk('uploads')->put('test' .'/pages', $image);
Files::create([
'post_image_captation' => 'image',
'post_image_path' => '/uploads' . $imagePath,
'pages_id' => $pages->id
]);
}
return $pages;
}
my blade
<div class="modal-body">
<form method="post" action="{{ route('admin.pages') }}">
#csrf
<div class="form-group">
<label for="recipient-name" class="col-form-label">Title</label>
<input type="text" class="form-control" name="title" id="title">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Meta Title</label>
<input type="text" class="form-control" name="meta_title" id="meta_title">
</div>
<div class="form-group">
<label for="recipient-name" class="col-form-label">Content</label>
<textarea class="ckeditor form-control" name="content" id="content"></textarea>
</div>
<div class="form-group">
<label for="images">Imagini</label>
<input type="file" class="form-control-file" name="images[]" id="images">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
Is there a solution to do what I created here in the easiest way possible?
Or is the logic good but I didn't put it into practice?
I think you modify a bit .Instead of Storage put you can use storeAs
if(isset($images)&&count((array)$images)){
foreach ($images as $image) {
$fileName = time().Str::random(8).'_'. $image->getClientOriginalName();
$image->storeAs('test/pages/', $fileName, 'uploads');
Files::create([
'post_image_captation' => 'image',
post_image_path' => '/uploads' . $fileName,
'pages_id' => $pages->id
]);
}
}
myiamge
I have 2 forms as tab in signup page when one form is submit and if have any error I want to redirect to that specific tab which have error but did not happen.
Here is my view
<?php include 'header.php'; ?>
<section class="services">
<div class="container">
<div class="signup-wrapper well" style="margin-bottom: 80px; margin-top: 80px;">
<div class="container">
<div class="services__main">
<h2 class="title title--main"><span class="title__bold">Sign Up</span><span class="line line--title"><span class="line__first"></span><span class="line__second"></span></span></h2>
</div>
<div class="aside-tabs__links">
Genrel User
Dealership
</div>
<div class="aside-tabs__blocks about-tab js-tab-block no-b-border" id="desc" >
<div class="col-md-5">
<form action="<?= base_url();?>Home/add_user" method="post" >
<!-- class="quick-form" -->
<div class="form-group">
<input type="text" class="form-control" name="fname" placeholder="Full Name" />
</div>
<?php echo form_error('fname'); ?>
<div class="form-group">
<input type="email" class="form-control" name="email" placeholder="Email" />
</div>
<?php echo form_error('email'); ?>
<div class="form-group">
<input type="password" class="form-control" name="password" placeholder="Password" />
</div>
<?php echo form_error('password'); ?>
<div class="form-group">
<input type="text" class="form-control" name="phone" placeholder="Phone #" />
</div>
<?php echo form_error('phone'); ?>
<div class="form-group">
<select class="select-2 form-control" name="city">
<option>Select City</option>
<?php foreach ($results as $result) { ?>
<option><?= $result->city; ?></option>
<?php } ?>
</select>
</div>
<?php echo form_error('city'); ?>
<div class="form-group">
<input type="submit" class="btn button button--red button--main pull-right" style="margin-bottom: 10px;" value="Sign Up">
</div>
</form>
</div>
</div>
<div class="aside-tabs__blocks about-tab js-tab-block no-b-border" id="rev" style="display: none;">
<div class="col-xs-5">
<form action="<?= base_url();?>Home/add_dealer" method="post" enctype="multipart/form-data">
<h4>Comapny Information</h4>
<hr>
<div class="form-group">
<input type="text" class="form-control" name="cname" placeholder="Company Name" />
</div>
<div class="form-group">
<input type="text" class="form-control" name="owner" placeholder="Owner Name" />
</div>
<div class="form-group">
<select class="select-2 form-control" name="city">
<option>Select City</option>
<?php foreach ($results as $result) { ?>
<option><?= $result->city; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<input type="text" class="form-control" name="address" placeholder="Office Location" />
</div>
<div class="form-group">
<input type="text" class="form-control" name="phone" placeholder="Office Phone" />
</div>
<div class="form-group">
<select name="business-type" class="form-control">
<option class="form-group">Products Deal</option>
<option class="form-group">Bikes</option>
<option class="form-group">Accessories</option>
<option class="form-group">Both</option>
</select>
</div>
<div class="form-group">
<input type="text" class="form-control" name="link" placeholder="social-link(optional)" />
</div>
<div class="form-group">
<button type="button" class="button button--custom--grey button--main btn" id="logo">Upload Logo</button>
<input type="file" class="form-control hidden" id="logo1" name="logo1" /><span id="mylogo">* Format must be jpg,jpeg or png</span>
</div>
<?php echo form_error('logo'); ?>
<div class="form-group">
<textarea class="form-control" name="descrp" placeholder="Description(optional)"></textarea>
</div>
<h4>Primary Information</h4>
<hr>
<div class="form-group">
<input type="text" class="form-control" name="email" placeholder="Email" />
</div>
<div class="form-group">
<input type="text" class="form-control" name="password" placeholder="Password" />
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn button button--red button--main pull-right" value="Sign Up">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
<?php include 'footer.php'; ?>
here is my controller
function add_dealer()
{
//echo "<pre>"; print_r($_FILES);
$config['upload_path'] = 'C:\xampp\htdocs\devilbirds\images\uploads';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$config['encrypt_name'] = 'TRUE';
$config['overwrite'] = 'FALSE';
$config['wm_text'] = 'Deveil Birds';
$config['wm_type'] = 'text';
$config['wm_font_path'] = 'C:\xampp\htdocs\devilbirds/fonts/fontawesome-webfont.ttf';
$config['wm_font_size'] = '16';
$config['wm_font_color'] = 'aabbcc';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'center';
$config['wm_padding'] = '20';
$this->load->library('upload', $config);
$this->image_lib->watermark();
$abc = $this->upload->do_upload('logo1');
$upload_data = $this->upload->data();
// var_dump($abc);exit();
$file_name = $upload_data['file_name'];
$this->form_validation->set_rules('cname','CName','trim|required');
$this->form_validation->set_rules('logo1','Logo1','trim');
$this->form_validation->set_rules('address','Address','trim');
$this->form_validation->set_rules('phone','Phone','trim|is_unique[bd_dealer.phone]');
$this->form_validation->set_rules('owner','Owner','trim');
$this->form_validation->set_rules('descrp','Descrp','trim');
$this->form_validation->set_rules('business-type','Business-type','trim');
$this->form_validation->set_rules('link','Link','trim');
$this->form_validation->set_rules('email','Email','trim|is_unique[bd_dealer.email]');
$this->form_validation->set_rules('password','Password','trim|min_length[5]|max_length[20]');
$this->form_validation->set_rules('city','City','trim');
if ($this->form_validation->run() == FALSE)
{
$data['error'] = $this->session->set_flashdata('errors');
$this->load->view('pages/signup',$data);// this is the link which loads my view i dont get how to go load that specific div from this url
}
else
{
$userData = array(
'company' => $this->input->post('cname'),
'logo' => $file_name,
'location' => $this->input->post('address'),
'phone' => $this->input->post('phone'),
'name' => $this->input->post('owner'),
'description' => $this->input->post('descrp'),
'business_type' => $this->input->post('business-type'),
'social_link' => $this->input->post('link'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
'city' => $this->input->post('city'));
$data = array(
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
'user_type' => '2');
//var_dump($userData);exit();
$this->Home_m->add_dealer($userData);
$this->Home_m->users($data);
redirect('Home/login');
}
}
I have two functions for two different forms in tabs. let suppose if i post my dealer form and this form have any issue then it will redirect to the signup page and it shows the pre-active tab which is general user signup. i want to redirect to the div that contain the form or dealer signup. any help will be appreciated , thanks in advance
In your controller when you get error do this.
for form one error
$data['error'] = $this->session->set_flashdata('errors');
$data['div1'] = "div1";
$this->load->view('pages/signup',$data);// this is the link which loads my view i dont get how to go load that specific div from this url ,i have pass div1 as parameter
For form two error
$data['error'] = $this->session->set_flashdata('errors');
$data['div2'] = "div2";
$this->load->view('pages/signup',$data);// this is the link which loads my view i dont get how to go load that specific div from this url ,i have pass div1 as parameter
In your view page
<script>
$(document).ready(function(){
var div1 = "<?php $div1; ?>";
var div2 = "<?php $div2; ?>";
if(div1=='' && div2==''){
$("#desc").show();
$("#rev").hide();
}else if(div1=='div1' && div2==''){
$("#desc").show();
$("#rev").hide();
}else if(div1=='' && div2=='div2'){
$("#desc").hide();
$("#rev").show();
}
})
</script>
div1
<div class="aside-tabs__blocks about-tab js-tab-block no-b-border" id="desc">
Div2
<div class="aside-tabs__blocks about-tab js-tab-block no-b-border" id="rev">
I hope it will help you.
I try to upload multiple files to an specific folder using laravel. I was able to do this with just one file. But after I tried to upload multiple files it didn't work. First of all I tried to make an foreach. But it didn't work I tried to find solutions on the internet but unfortunately I didn't find one. Can anybody help me?
public function store(Request $request) {
// dd(request()->all());
$this->validate(request(), [
'name' => 'required|unique:lessons|max:20',
'type' => 'required',
'description' => 'required',
'price' => 'required',
'main_picture' => 'required',
'pictures' => 'required'
]);
$input = $request->all();
$images= array();
if($files=$request->file('images')){
foreach($files as $file){
$name=$file->getClientOriginalName();
$file->move('lesson images',$name);
$images[]=$name;
}
}
$lesson = Lesson::create( [
'name' =>$input['name'],
'type' => $input['type'],
'description' =>$input['description'],
'price' => $input['price'],
'main_picture' =>$input['main_picture'],
'pictures'=> implode("|",$images),
]);
$image_name = $request->file('main_picture')->getClientOriginalName();
$id = $lesson->id;
if($request->hasFile('main_picture')) {
$file = $request->file('main_picture');
$file->move('lesson images', $id . "-main-" . $image_name);
}
return redirect('/lessenoverzicht');
}
HTML:
<form method="post" enctype="multipart/form-data" action="/lessenoverzicht/toevoegen">
{{ csrf_field() }}
<div class="form-group">
<label for="name"><span class='required'>*</span>Naam les:</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Voer naam les in..">
</div>
<div class="form-group">
<label for="exampleFormControlSelect1"><span class='required'>*</span>Type</label>
<select name='type' class="form-control" id="type">
<option value="" disabled selected>Select your option</option>
<option value='les'>Les</option>
<option value='workshop'>Workshop</option>
</select>
</div>
<div class="form-group">
<label for="description"><span class='required'>*</span>Omschrijving:</label>
<textarea class="form-control" id="description" name="description" rows="10" placeholder="Voer omschrijving in..."></textarea>
</div>
<label for="description"><span class='required'>*</span>Prijs:</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">€</span>
</div>
<input type="number" value="0.00" min="0" step="1.00" class="form-control" id='price' name='price'>
</div>
<div class="form-group">
<label for="main_picture"><span class='required'>*</span>Main Image:</label>
<input type="file" class='form-control' id='main_picture' name="main_picture">
</div>
<div class="form-group">
<label for="picture">Afbeelding(en) omschrijving:</label>
<input type="file" class='form-control' id='picture' name="pictures" multiple>
</div>
<div class="form-group">
#include('layouts.errors')
</div>
<button type="submit" class="btn btn-primary">Toevoegen</button>
</form>
Can you try the below change in your code? I have only added Array type name property name="pictures[]"
<input type="file" class='form-control' id='picture' name="pictures[]" multiple>
Sample Code:
<form class="form-horizontal" enctype="multipart/form-data" method="post" action="/details">
and this for multiple selection:
<input required type="file" class="form-control" name="images[]" placeholder="address" multiple>
PHP logic
public function store(request $request) {
$input=$request->all();
$images=array();
if($files=$request->file('images')){
foreach($files as $file){
$name=$file->getClientOriginalName();
$file->move('image',$name);
$images[]=$name;
}
}
/*Insert your data*/
Detail::insert( [
'images'=> implode("|",$images),
'description' =>$input['description'],
//you can put other insertion here
]);
return redirect('redirecting page');
}
I am unable to upload a image in the destination folder in codeigniter, I created one controller under the controller/admin folder with a name called site. And I added one model under the model folder with a name called model_view, and finally I created one view in the view folder with a name called view_addsite. And I created one table in the mysql with a name called sitesettings and 14 columns are added in that table. Problem hear is all fields are added in the table except image. please find the code.
controller(site)::
===========
public function add()
{
$datte = date('Y-m-d H:i:s');
if(!$this->input->post('buttonSubmit'))
{
$data['message'] = '';
$this->load->view('admin/view_addsite', $data);
}
else
{
//$this->load->library('form_validation');
if($this->form_validation->run('addsite'))
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_width'] = '2048';
$config['max_height'] = '2048';
$this->load->library('upload', $config);
$title = $this->input->post('title');
$name = $this->input->post('name');
$admin = $this->input->post('admin');
$mail = $this->input->post('mail');
$phone = $this->input->post('phone');
$contact=$this->input->post('contact');
$fb=$this->input->post('fb');
$tw=$this->input->post('tw');
$yt=$this->input->post('yt');
$in=$this->input->post('in');
$gp=$this->input->post('gp');
$ft=$this->input->post('ft');
$this->upload->do_upload('image');
$data = $this->upload->data('image');
$image= $data['file_name'];
$this>model_site>
insert($title,$image,$name,$admin,$mail,
$phone,$contact,$fb,$tw,$yt,$in,$gp,$ft);
$this->session->set_flashdata('message','site Successfully
Created.');
redirect(base_url('admin/site'));
}
else
{
$data['message'] = validation_errors();
$this->load->view('admin/view_addsite', $data);
}
}
}
Model(model_site)::
===================
public function
insert($title,$image,$name,$admin,$mail,$phone,$contact,
$fb,$tw,$yt,$in,$gp,$ft)
{
$data = array(
'admintitle' => $title,
'logo' => $image,
'fromname' => $name,
'adminemail'=> $admin,
'receivemail' => $mail,
'phonenumber' => $phone,
'contactaddress' => $contact,
'facebook' => $fb,
'twitter'=>$tw,
'youtube' => $yt,
'instagram' => $in,
'googleplus' => $gp,
'footer' => $ft,
);
$this->db->insert('sitesettings', $data);
}
view(view_addsite)::
===================
<!-- page content -->
<div class="right_col" role="main">
<div class="">
<div class="page-title">
<div class="title_left">
<h3>Sitesettings</h3>
</div>
</div><div class="clearfix"></div>
<hr>
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Add a new Site</h2>
<ul class="nav navbar-right panel_toolbox">
<li><a class="collapse-link"><i class="fa fa-
chevron-up"></i></a></li>
<li><a class="close-link"><i class="fa fa-close">
</i></a></li>
</ul>
<div class="clearfix"></div>
</div>
<div class="x_content">
<label><?php echo $message; ?></label>
<form method="post">
<fieldset>
<div class="form-group">
AdminPage Title : <input class="form-control"
placeholder="Admin Title" name="title" id="title"
type="text" ><span id="user-availability-status">
</span>
<div class="form-group">
Select image to upload:
<input type="file" name="fileToUpload"
id="fileToUpload">
</form>
<div class="form-group">
From Name : <input class="form-control"
placeholder="Form Title" name="name" id="name" type="text"
><span id="user-availability-status"></span>
<div class="form-group">
Admin Email Address : <input class="form-control"
placeholder="Admin Email" name="admin" id="admin"
type="text" onBlur="checkAvailability()" ><span
id="user-availability-status"></span>
<div class="form-group">
Receive Mail Address for Contact Us Form : <input
class="form-control" placeholder="Receive Email"
name="mail" id="mail" type="text"
onBlur="checkAvailability()" ><span id="user-availability-
status"></span>
</div>
<div class="form-group">
Phone number: <input class="form-control"
placeholder="Phone Number" name="phone" id="phone"
type="text" onBlur="checkAvailability()" ><span id="user-
availability-status"></span>
</div>
<div class="form-group">
Contact Adress : <input class="form-control"
placeholder="Contact Address" name="contact" id="contact"
type="text" onBlur="checkAvailability()" ><span
id="user-availability-status"></span>
</div>
<div class="form-group">
Facebook : <input class="form-control" placeholder="Facebook"
name="fb" id="fb" type="text" onBlur="checkAvailability()" >
<span id="user-availability-status"></span>
</div>
<div class="form-group">
Twitter : <input class="form-control" placeholder="Twitter"
name="tw" id="tw" type="text" onBlur="checkAvailability()" >
<span id="user-availability-status"></span>
</div>
<div class="form-group">
Youtube : <input class="form-control"
placeholder="Youtube" name="yt" id="yt" type="text"
onBlur="checkAvailability()" ><span id="user-availability-
status"></span>
</div>
<div class="form-group">
Instagram : <input class="form-control"
placeholder="Instagram" name="in" id="in" type="text"
onBlur="checkAvailability()" ><span id="user-availability-
status"></span>
</div>
<div class="form-group">
Google Plus: <input class="form-control"
placeholder="Google Plus" name="gp" id="gp" type="text"
onBlur="checkAvailability()" ><span id="user-availability-
status"></span>
</div>
<div class="form-group">
Footer: <input class="form-control"
placeholder="Footer" name="ft" id="ft"
type="text" onBlur="checkAvailability()" ><span id="user-
availability-status"></span>
</div>
<input type="submit" name="buttonSubmit"
value="add" class="btn btn-success" />
</fieldset>
</form>
</div> <!-- /content -->
</div><!-- /x-panel -->
</div> <!-- /col -->
</div> <!-- /row -->
</div>
</div> <!-- /.col-right -->
<!-- /page content -->
<?php $this->load->view('admin/partials/admin_footer'); ?>
<?php if($this->session->flashdata('message') != NULL) : ?>
<script>
swal({
title: "Success",
text: "<?php echo $this->session->flashdata('message'); ?>",
type: "success",
timer: 1500,
showConfirmButton: false
});
</script>
<?php endif ?>
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
for more detail see:upload file with codeigniter
You are missing
enctype="multipart/form-data"
on your form tag and also remove the </form> just after the image input box.
Controller:
$doc_1 = "uploads/img_1/";
if (isset($_FILES['userfile_1']) && !empty($_FILES['userfile_1'])) {
$filename = pathinfo($_FILES['userfile_1']['name']);
if (move_uploaded_file($_FILES['userfile_1']['tmp_name'], $doc_1.$filename['basename'])) {
$attch_1 = base_url().$doc_1.$filename['basename'];
}
else {
$attch_1 = "na";
}
}
view:
<?php echo form_open_multipart("store_property", ['class'=>'form-horizontal']); ?>
<input type="file" name="userfile_1" />
I made a user registration form on the CodeIgniter framework so users can registrate to my website. Now the only thing that doesn't work is that I cant upload a profile picture. When I click on the register button I'm getting 2 errors. I want the profile picture to be uploaded in the product_foto column.
This is my view file: (register.php) :
<form action="" method="POST" enctype='multipart/form-data'>
<div class="form-group">
<label for="voornaam">Voornaam</label>
<input class="form-control" name="voornaam" id="voornaam" type="text">
</div>
<div class="form-group">
<label for="achternaam">Achternaam</label>
<input class="form-control" name="achternaam" id="achternaam" type="text">
</div>
<div class="form-group">
<label for="achternaam">Straat en huisnummer</label>
<input class="form-control" name="straat" id="straat" type="text">
</div>
<div class="form-group">
<input class="form-control" name="huisnummer" id="huisnummer" type="text">
</div>
<div class="form-group">
<label for="huisnummer">Huisnummer</label>
<input class="form-control" name="huisnummer" id="huisnummer">
</div>
<div class="form-group">
<label for="postcode">Postcode</label>
<input class="form-control" name="postcode" id="postcode">
</div>
<div class="form-group">
<label for="woonplaats">Woonplaats</label>
<input class="form-control" name="woonplaats" id="woonplaats">
</div>
<div class="form-group">
<label for="email">Email adres</label>
<input class="form-control" name="email" id="email" type="emai">
</div>
<div class="form-group">
<label for="wachtwoord">Wachtwoord</label>
<input class="form-control" name="wachtwoord" id="wachtwoord" type="password">
</div>
<div class="form-group">
<label for="wachtwoord">Herhaal wachtwoord</label>
<input class="form-control" name="wachtwoord2" id="wachtwoord" type="password">
</div>
<div class="form-group">
<label for="profiel_foto">Profiel foto</label>
<input class="form-control" type="file" name="profiel_foto" id="profiel_foto">
</div>
<div class="form-group">
<label for="beschrijving">Beschrijving</label>
<input class="form-control" name="beschrijving" id="beschrijving">
</div>
<div class="form-group">
<label for="geboortedatum">Geboortedatum</label>
<input class="form-control" name="geboortedatum" id="geboortedatum" type="date">
</div>
<div class="form-group">
<label for="geslacht">Geslacht</label>
<select class="form-control" id="geslacht" name="geslacht">
<option value="Man">Man</option>
<option value="Vrouw">Vrouw</option>
</select>
</div>
<div>
<button class="btn btn-primary" name="register">Registreren</button>
</div>
</form>
This is the register code in the controller:
public function register() {
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$this->load->library('upload', $config);
$this->input->post('profiel_foto');
$data_upload_files = $this->upload->data();
$image = $data_upload_files['./upload/'];
//voeg gebruiker toe aan database
$data = array(
'voornaam' => $_POST['voornaam'],
'achternaam' => $_POST['achternaam'],
'email' => $_POST['email'],
'wachtwoord' => ($_POST['wachtwoord']),
'startdatum' => date('Y-m-d'),
'postcode' => $_POST['postcode'],
'huisnummer' => $_POST['huisnummer'],
'woonplaats' => $_POST['woonplaats'],
'beschrijving' => $_POST['beschrijving'],
'geboortedatum' => $_POST['geboortedatum'],
'geslacht' => $_POST['geslacht'],
'profiel_foto' => $image
);
$this->db->insert('users', $data);
$this->session->set_flashdata("success", "Uw account is nu geregistreerd, u kunt nu inloggen");
redirect("auth/register", "refresh");
}
And these are the 2 errors I'm getting when I'm trying to registrate:
PHP Error was encountered
Severity: Notice
Message: Undefined index: ./upload/
Filename: controllers/Auth.php
Line Number: 131
Backtrace:
File: /home/ubuntu/workspace/application/controllers/Auth.php
Line: 131
Function: _error_handler
File: /home/ubuntu/workspace/index.php
Line: 315
Function: require_once
A Database Error Occurred
Error Number: 1048
Column 'profiel_foto' cannot be null
INSERT INTO `users` (`voornaam`, `achternaam`, `email`, `wachtwoord`, `startdatum`, `postcode`, `huisnummer`, `woonplaats`, `beschrijving`, `geboortedatum`, `geslacht`, `profiel_foto`) VALUES ('hallo', 'hallo', 'hallo#gmail.com', 'hallo', '2017-06-28', 'hallo', 'hallo', 'hallo', 'hallo', '2017-06-10', 'Man', NULL)
Filename: controllers/Auth.php
Line Number: 149
Your First error is being caused by:
$image = $data_upload_files['./upload/'];
As stated './upload/' is not a valid index nor is an existing one in that array. It's not clear where you have defined that.
Next: What does this line do?
$this->input->post('profiel_foto');
Next: Debug: Inspect your array $data prior to the insert and check it.
// Snip of other code
$data = array(
'voornaam' => $_POST['voornaam'],
'achternaam' => $_POST['achternaam'],
'email' => $_POST['email'],
'wachtwoord' => ($_POST['wachtwoord']),
'startdatum' => date('Y-m-d'),
'postcode' => $_POST['postcode'],
'huisnummer' => $_POST['huisnummer'],
'woonplaats' => $_POST['woonplaats'],
'beschrijving' => $_POST['beschrijving'],
'geboortedatum' => $_POST['geboortedatum'],
'geslacht' => $_POST['geslacht'],
'profiel_foto' => $image
);
$this->db->insert('users', $data);
var_dump($data);
exit();
// Snip of other code
And read the user guide as I stated above in my comments... Cause I aint writing that out here for you... That should get you started.