Welcome Guest, Not a member yet? Register   Sign In
$_FILES Array getting empty when using $this->form_validation->run()
#11

$lastid = $this->db->insert_id();

this returns 0
Reply
#12

When I use $result its working but getting the value -1

Means if the last inserted id is 12, I'm getting 11 in the result variable.
Reply
#13

Probably you deleted one of the records before. So, if you are in a development period please go to phpmyadmin and clear the datas in the table. Then go to the Settings sections (top menu of phpmyadmin) and set AUTO_INCREMENT as 0, in order to start from 1, then try posting the form again.

(If I'm not wrong Auto_INCREMENET will be 0 for the start. If not, then insert 1 Smile )


The second option:  you can add+1 to your id within your php codes. But I'd go with the first one.
Reply
#14

(06-12-2019, 01:45 AM)demyr Wrote: Probably you deleted one of the records before. So, if you are in a development period please go to phpmyadmin and clear the datas in the table. Then go to the Settings sections (top menu of phpmyadmin) and set AUTO_INCREMENT as 0, in order to start from 1, then try posting the form again.

(If I'm not wrong Auto_INCREMENET will be 0 for the start. If not, then insert 1 Smile )


The second option:  you can add+1 to your id within your php codes. But I'd go with the first one.

Finally I got The issue is with the database operations.

property_images table has fields - id,path,propertyid

propertyid is the last inserted id form the first query(Insert property details). But when i use the id to insert property images its not working.

I tried the propertyid as simply value then its working, When i use the propertyid as last inserted id which return after inserting the property details is not working.

Model

PHP Code:
function addNewProperty($propertyInfo)
 
     {
 
         $this->db->trans_start();
 
         $this->db->insert('tbl_properties'$propertyInfo);

 
         $insert_id $this->db->insert_id();

 
         $this->db->trans_complete();

 
         return $insert_id;
 
     }

 
     function addPropertyImgs($propertyImgs)
 
     {
 
         $this->db->trans_start();
 
         $this->db->insert('tbl_property_images'$propertyImgs);

 
         $insert_id $this->db->insert_id();

 
         $this->db->trans_complete();

 
         //return $insert_id;

 
     
Reply
#15

Here Everything got worked, Expect the insertion of images into table. When I use the $result to propertyid to insert the property images its not working also it break the file upload process also.

If I give the value anything instead of $result variable. its working.


PHP Code:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Class : Login (LoginController)
 * Login class to control to authenticate user credentials and starts user's session.
 * @author : Kishor Mali
 * @version : 1.1
 * @since : 15 November 2016
 */
class Home extends CI_Controller
{
 
   /**
     * This is default constructor of the class
     */
 
   public function __construct()
 
   {
 
     parent::__construct();
 
     $this->load->model('property_model');

 
    }

 
   /**
     * Index Page for this controller.
     */
 
   public function index()
 
   {
 
       $data = array('title'=> 'Vierra Property Broker''main_content'=>'home');
 
       $this->load->view('template'$data);

 
   }

 
   /**
     * Loaading the submit property form.
     */

 
   public function listProperty()

 
   {

 
     $data = array('title'=> 'Vierra Property Broker - Submit your Property''main_content'=>'submit_property');
 
     $this->load->view('template'$data);




 
   }



 
   function addProperty()
 
   {

 
       $this->load->library('form_validation');




 
          //$this->form_validation->set_rules('prop_title','Villa Title','trim|required|max_length[128]');
 
         // $this->form_validation->set_rules('prop_status','Status','trim|required');
 
          //$this->form_validation->set_rules('prop_type','Type','trim|required');
 
          //$this->form_validation->set_rules('prop_price','Price','trim|required|numeric');
 
          //$this->form_validation->set_rules('prop_sqft','Sqft','trim|required|numeric');
 
          $this->form_validation->set_rules('prop_rooms','Rooms','trim|required|numeric');
 
          $this->form_validation->set_rules('prop_address','Address','trim|required|max_length[200]');
 
          $this->form_validation->set_rules('prop_owner_phone','Mobile Number','required|min_length[10]');
 
          $this->form_validation->set_rules('prop_owner_name','Owner Name','required|min_length[5]');
 
          $this->form_validation->set_rules('prop_owner_email','Owner Email','required|valid_email');
 
          //$this->form_validation->set_rules('prop_detailed_info','Detailed Info','trim|required|max_length[2000]');
 
          //$this->form_validation->set_rules('prop_status','Current Status','trim|required');

 
          if($this->form_validation->run())
 
          {



 
              $prop_title ucwords(strtolower($this->security->xss_clean($this->input->post('prop_title'))));
 
              $prop_status ucwords(strtolower($this->security->xss_clean($this->input->post('prop_status'))));
 
              $prop_type ucwords(strtolower($this->security->xss_clean($this->input->post('prop_type'))));
 
              $prop_price $this->security->xss_clean($this->input->post('prop_price'));
 
              $prop_sqft $this->security->xss_clean($this->input->post('prop_sqft'));
 
              $prop_rooms $this->security->xss_clean($this->input->post('prop_rooms'));
 
              $prop_address $this->security->xss_clean($this->input->post('prop_address'));
 
              $prop_owner_name $this->security->xss_clean($this->input->post('prop_owner_name'));
 
              $prop_owner_email $this->security->xss_clean($this->input->post('prop_owner_email'));
 
              $prop_owner_phone $this->security->xss_clean($this->input->post('prop_owner_phone'));
 
              $prop_detailed_info $this->security->xss_clean($this->input->post('prop_detailed_info'));
 
              $prop_current_status $this->security->xss_clean($this->input->post('prop_current_status'));









 
              //$userInfo = array('email'=>$email, 'password'=>getHashedPassword($password), 'roleId'=>$roleId, 'name'=> $name,
 
                                  //'mobile'=>$mobile, 'createdBy'=>$this->vendorId, 'createdDtm'=>date('Y-m-d H:i:s'));

 
               $propertyInfo = array('title'=>$prop_title'status'=>$prop_status'type'=>$prop_type'price'=>$prop_price,
 
                                     'sqft'=>$prop_sqft'rooms'=>$prop_rooms'address'=>$prop_address'name'=>$prop_owner_name,
 
                                     'email'=>$prop_owner_email'phone'=>$prop_owner_phone'detailedInfo'=>$prop_detailed_info,
 
                                     'currentStatus'=>$prop_current_status);



 
              $result $this->property_model->addNewProperty($propertyInfo);

 
            }





 
              if($result 0)

 
              {

 
                 //$propertyImgUpload = uploadImages($result);
 
                  $this->session->set_flashdata('success''Thank you for submiting your property with us!, Our team will contact you shortly');
 
              }
 
              else
 
              {
 
                  $this->session->set_flashdata('error''Submission of property failed, Contact [email protected]');
 
              }




 
              if (!empty($_FILES)) {
 
              $is_image "Yes There is Image!";
 
              $count_img count($_FILES['file']['name']);
 
              foreach($_FILES['file']['tmp_name'] as $key => $value) {

 
               $tempFile $_FILES['file']['tmp_name'][$key];
 
               $fileName $_FILES['file']['name'][$key];
 
               $targetPath 'property-images/';
 
               $targetFile $targetPath $fileName ;

 
               //$this->load->model('user_model');

 
               $imgData = array('path'=>$targetFile,'propertyid'=>$result);

 
               if(move_uploaded_file($tempFile$targetFile))
 
               {


 
                   $this->property_model->addPropertyImgs($imgData);


 
               }


 
              }
 
              }


 
              redirect('/submit-property');

 
          }





 
          }


function 
check_captcha()
{


 
  if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){
 
    $gCaptcha $_POST['g-recaptcha-response'];
 
   // Google reCAPTCHA API secret key
 
  $secretKey '6LekZagUAAAAALlguY5sjircXO6Adre6BDDHQWV_';

 
  // Verify the reCAPTCHA response
 
  $verifyResponse file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$gCaptcha);

 
  // Decode json data
 
  $responseData json_decode($verifyResponse);

 
  print_r($responseData);

}
else {
//$this->load->view('upload_index');

}

}


?>


Expect this everything working fine now,

PHP Code:
$imgData = array('path'=>$targetFile,'propertyid'=>$result);

$this->property_model->addPropertyImgs($imgData); 


The everything work if I change $result to simply any value. But I need the reference of the property to insert images.
Reply
#16

Hey again.

Take this part out of your codes: 
Code:
 if($result > 0)

              {

                 //$propertyImgUpload = uploadImages($result);
                  $this->session->set_flashdata('success', 'Thank you for submiting your property with us!, Our team will contact you shortly');
              }
              else
              {
                  $this->session->set_flashdata('error', 'Submission of property failed, Contact [email protected]');
              }
 


And add $result= here, just before the $this->property_model->addPropertyImgs($imgData);

Code:
if(move_uploaded_file($tempFile, $targetFile))
               {


                   $result = $this->property_model->addPropertyImgs($imgData);


               }

and then run checking 

Code:
if($result)

              {

                 //$propertyImgUpload = uploadImages($result);
                  $this->session->set_flashdata('success', 'Thank you for submiting your property with us!, Our team will contact you shortly');
              }
              else
              {
                  $this->session->set_flashdata('error', 'Submission of property failed, Contact [email protected]');
              }

In short, 2 $result variables will check for the same result.
Reply
#17

What's the value and the type of the variable $inserted_id.
Chage your function into your model:

PHP Code:
function addNewProperty($propertyInfo)
 
     {
 
         $this->db->trans_start();
 
         $this->db->insert('tbl_properties'$propertyInfo);

 
         $insert_id $this->db->insert_id();

 
         $this->db->trans_complete();

 
         var_dump($insert_id);
die();
 
     
post the result
Reply
#18

(06-12-2019, 03:37 AM)hc-innov Wrote: What's the value and the type of the variable $inserted_id.
Chage your function into your model:

PHP Code:
function addNewProperty($propertyInfo)
 
     {
 
         $this->db->trans_start();
 
         $this->db->insert('tbl_properties'$propertyInfo);

 
         $insert_id $this->db->insert_id();

 
         $this->db->trans_complete();

 
         var_dump($insert_id);
die();
 
     
post the result
Its integer value.
Reply
#19

is it the right value (the right id inserted and not 0) ?
Reply
#20

(06-12-2019, 03:48 AM)sarath_unrelax Wrote:
(06-12-2019, 03:37 AM)hc-innov Wrote: What's the value and the type of the variable $inserted_id.
Chage your function into your model:

PHP Code:
function addNewProperty($propertyInfo)
 
     {
 
         $this->db->trans_start();
 
         $this->db->insert('tbl_properties'$propertyInfo);

 
         $insert_id $this->db->insert_id();

 
         $this->db->trans_complete();

 
         var_dump($insert_id);
die();
 
     
post the result
Its integer value.


Buddy I GET : int 24
Reply




Theme © iAndrew 2016 - Forum software by © MyBB