Search the Community
Showing results for tags 'codeigniter'.
-
I am pretty new to codeigniter and need help. I have a view that list 3 names with a check box to each name. What i am trying to do is post the items that are checked off to a database.(clientid, camapignid values of only selected). Here are the tables in my database. id - auto increment clientId campaignId creationdate Here is the code for my view: <html> <head> <title>Client View</title> <style type="text/css"> label{ display: block; } </style> </head> <body> <h2>Insert</h2> <?php echo form_open('site/create_client'); ?> <p> <input type="checkbox" name="clientid[]" value="10"> - Fred <input type="checkbox" name="clientid[]" value="20"> - Bob <input type="checkbox" name="clientid[]" value="30"> - Mary <input type="hidden" name="campaignid[]" value="2"> </p> <p> <input type="submit" value="Submit"/> </p> <?php echo form_close(); ?> </body> </html> Here is the code for my controller: <?php class Client extends CI_Controller{ function index(){ $this->load->view('client'); } function create(){ $datetime = date('Y-m-d H:i:s'); $data = array( 'clientid'=> $this->input->post('clientid'), 'campaignid'=> $this->input->post('campaignid'), 'creationdate'=> $datetime ); $this->client->add_record($data); $this->index(); } } Here is the code for my model: <?php class client extends CI_Model{ function add_record($data){ $this->db->insert('campaign_to_client', $data); return; } } I know I am missing some kind of loop somewhere but cant figure it out. Thanks!
-
Hi guys, finally codeigniter seems to make a little sense when I gave it another go making a simple project and learning individual things to get there as opposed to just following the “blog tutorial”.. However I am trying to submit a form and do it through ajax/jquery so that the other page doesn’t show and everything happens in one page. This is from my view where the form and jquery is: jquery: <script> $(function(){ $("#form-signin").submit(function(){ dataString = $("#form-signin").serialize(); $.ajax({ type: "POST", url: "<?php echo base_url(); ?>index.php/welcome/addmovie", data: dataString, success: function(data){ alert('Successful!'); } }); return false; //stop the actual form post !important! }); }); </script> form: <form class="form-signin" method="post" id="form-signin"> <h4 class="form-signin-heading">Add a Movie</h4> <input type="text" class="input-block-level" placeholder="Movie Title"> <input type="text" class="input-block-level" placeholder="URL"> <input type="number" class="" min="1" max="100" placeholder="Jamies Score"> <input type="number" class="" min="1" max="100" placeholder="Kellys Score"> <button class="btn btn-large btn-primary" type="submit">Add</button> </form> It seems nothing happens when you click the submit button and I’ve put the script at the bottom of the page just before </body> as it seems when I put it under the form it doesn’t load the rest of the code below it? I am very new with jquery so please be kind. I don’t have anything in the script which the jquery should load (public function addmovie in the welcome controller) so it should return successfully I think? I hope someone can help me out! PS Using this tutorial: http://optimiseblog....niter-and-ajax/
- 1 reply
-
- jquery
- codeigniter
-
(and 1 more)
Tagged with:
-
hello guys i have a problem. All i want is to pass my information coming from my multidimensional array. I try to create a function named r_implode that extract array into string but i dont know how to put it in the database. here's my code hope you can help me. //get array information $products = unserialize($this->session->userdata('product_list')); //print array information, works well foreach($products as $element => $inner_array){ echo "<strong>Product ID: ".$element."</strong><br>"; foreach($inner_array as $items){ echo $items."<br>"; } } //HOw CAN I PASS THE ARRAY INFORMATION TO MY DATABASE? //extract array into string works well function r_implode( $glue, $pieces ){ foreach( $pieces as $r_pieces ){ if( is_array( $r_pieces )){ $retVal[] = r_implode( $glue, $r_pieces ); }else{ $retVal[] = $r_pieces; } } return implode( $glue, $retVal ); } echo r_implode(',',$products)."\n"; example of my array layout: Product ID: 2 2 NOKIA 5110 Cellphone 500.00 1 500 NOKI2012-84353 Product ID: 3 3 HP IPAQ RW6828 Cellphone 1500.00 1 1500 HP I2012-08386
-
Hi guys, Been fighting with this and can't get it to work. Basically, on submit, session is being updated but data is not being sent to the database. Here is my view_profile.php <?php if(!$this->session->userdata('id')) { redirect(base_url().'admin'); } ?> <section class="content-header"> <div class="content-header-left"> <h1>Edit Profile</h1> </div> </section> <section class="content" style="min-height:auto;margin-bottom: -30px;"> <div class="row"> <div class="col-md-12"> <?php if($this->session->flashdata('error')) { ?> <div class="callout callout-danger"> <p><?php echo $this->session->flashdata('error'); ?></p> </div> <?php } if($this->session->flashdata('success')) { ?> <div class="callout callout-success"> <p><?php echo $this->session->flashdata('success'); ?></p> </div> <?php } ?> </div> </div> </section> <section class="content"> <div class="row"> <div class="col-md-12"> <div class="nav-tabs-custom"> <ul class="nav nav-tabs"> <li class="active"><a href="#tab_1" data-toggle="tab">Update Information</a></li> <li><a href="#tab_2" data-toggle="tab">Update Photo</a></li> <li><a href="#tab_3" data-toggle="tab">Update Password</a></li> </ul> <div class="tab-content"> <div class="tab-pane active" id="tab_1"> <?php echo form_open(base_url().'admin/profile/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">Display Name <span>*</span></label> <div class="col-sm-4"> <input type="text" class="form-control" name="name" value="<?php echo $this->session->userdata('name'); ?>"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">Email Address <span>*</span></label> <div class="col-sm-4"> <input type="text" class="form-control" name="email" value="<?php echo $this->session->userdata('email'); ?>"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">Phone <span>*</span></label> <div class="col-sm-4"> <input type="text" class="form-control" name="phone" value="<?php echo $this->session->userdata('phone'); ?>"> </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="form1">Update Information</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> <div class="tab-pane" id="tab_2"> <?php echo form_open_multipart(base_url().'admin/profile/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">Existing Photo</label> <div class="col-sm-6" style="padding-top:6px;"> <?php if($this->session->userdata('photo') ==''): ?> <img src="<?php echo base_url(); ?>public/img/no-photo.jpg" class="existing-photo" alt="profile photo" width="140"> <?php else: ?> <img src="<?php echo base_url(); ?>public/uploads/<?php echo $this->session->userdata('photo'); ?>" class="existing-photo" width="140"> <?php endif; ?> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">New Photo</label> <div class="col-sm-6" style="padding-top:6px;"> <input type="file" name="photo"> </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="form2">Update Photo</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> <div class="tab-pane" id="tab_3"> <?php echo form_open(base_url().'admin/profile/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">Password </label> <div class="col-sm-4"> <input type="password" class="form-control" name="password"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">Retype Password </label> <div class="col-sm-4"> <input type="password" class="form-control" name="re_password"> </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="form3">Update Password</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> </div> </div> </div> </div> </section> Here is my controller - Profile.php <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Profile extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('admin/Model_common'); $this->load->model('admin/Model_profile'); } public function index() { $data['setting'] = $this->Model_common->get_setting_data(); $this->load->view('admin/view_header',$data); $this->load->view('admin/view_profile',$data); $this->load->view('admin/view_footer'); } public function update() { $error = ''; $success = ''; $data['setting'] = $this->Model_common->get_setting_data(); if(isset($_POST['form1'])) { $valid = 1; $this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email'); if($this->form_validation->run() == FALSE) { $valid = 0; $error = validation_errors(); } if($valid == 1) { $form_data = array( 'email' => $_POST['email'], 'name' => $_POST['name'], 'phone' => $_POST['phone'] ); $this->Model_profile->update($form_data); $success = 'Profile Information is updated successfully!'; $this->session->set_userdata($form_data); $this->session->set_flashdata('success',$success); redirect(base_url().'admin/profile'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'admin/profile'); } } if(isset($_POST['form2'])) { $valid = 1; $path = $_FILES['photo']['name']; $path_tmp = $_FILES['photo']['tmp_name']; if($path!='') { $ext = pathinfo( $path, PATHINFO_EXTENSION ); $file_name = basename( $path, '.' . $ext ); $ext_check = $this->Model_common->extension_check_photo($ext); if($ext_check == FALSE) { $valid = 0; $data['error'] = 'You must have to upload jpg, jpeg, gif or png file<br>'; } } else { $valid = 0; $data['error'] = 'You must have to select a photo<br>'; } if($valid == 1) { // removing the existing photo unlink('./public/uploads/'.$this->session->userdata('photo')); // updating the data $final_name = 'user-'.'.'.$ext; move_uploaded_file( $path_tmp, './public/uploads/'.$final_name ); $form_data = array( 'photo' => $final_name ); $this->Model_profile->update($id,$form_data); $success = 'Photo is updated successfully!'; $this->session->set_userdata($id,$form_data); $this->session->set_flashdata('success',$success); redirect(base_url().'admin/profile'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'admin/profile'); } } if(isset($_POST['form3'])) { $valid = 1; $this->form_validation->set_rules('password', 'Password', 'trim|required'); $this->form_validation->set_rules('re_password', 'Retype Password', 'trim|required|matches[password]'); if($this->form_validation->run() == FALSE) { $valid = 0; $error = validation_errors(); } if($valid == 1) { $form_data = array( 'password' => md5($_POST['password']) ); $this->Model_profile->update($id,$form_data); $success = 'Password is updated successfully!'; $this->session->set_userdata($id,$form_data); $this->session->set_flashdata('success',$success); redirect(base_url().'admin/profile'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'admin/profile'); } } $data['setting'] = $this->Model_common->get_setting_data(); $this->load->view('admin/view_header',$data); $this->load->view('admin/view_profile',$id,$data); $this->load->view('admin/view_footer'); } } And finally, my Model_profile.php (only need to update) No errors etc. Any help would be appreciated. Cheers, Dan <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Model_profile extends CI_Model { function update($id) { $this->db->where('id',$id); $this->db->update('tbl_team_member',$data); } }
- 2 replies
-
- codeigniter
- php7
-
(and 1 more)
Tagged with:
-
Good Day Everyone, I recently was looking for a decent framework to build a new website on and at a glance Yii Framework (http://www.yiiframework.com/) seemed to suit my needs. But after starting to work with I noticed it is perhaps a little too user friendly. I am now tossing up between CodeIgniter (http://ellislab.com/codeigniter) and PHPDevShell (http://www.phpdevshell.org/). If anyone has any prior experience with either frameworks I would love to hear your thoughts. While Yii generates a lot of code for you, providing a base to work off. I have always preferred building functionality myself in conjunction with a framework that doesn't provide a base for you. Any thoughts, ideas are welcome. Kind Regards, Ace
- 5 replies
-
- framework
- codeigniter
-
(and 1 more)
Tagged with: