When I tried to print the data, it is being printed correctly. However, I’m having trouble with the view file it’s not populating the dropdown as expected. If anyone knows what might be wrong, please let me know. I think it could be a silly mistake, but I’m not sure what it is. 😓
profile.php – view file
<body>
<!-- upload_form.php -->
<form method="post" action="<?php echo base_url('ImageUpload/add_image'); ?>" enctype="multipart/form-data" class="file-upload mb-5">
<div class="container">
<div class="row mb-5 gx-5">
<!-- Contact detail -->
<div class="col-xxl-8 mb-5 mb-xxl-0">
<div class="bg-secondary-soft px-4 py-5 rounded">
<div class="row g-3">
<h4 class="mb-4 mt-0 fw-semibold">Contact detail</h4>
<!-- First Name -->
<div class="col-md-6">
<label class="form-label">First Name*</label>
<input type="text" class="form-control" placeholder="" name="first_name" aria-label="First name">
</div>
<!-- Last name -->
<div class="col-md-6">
<label class="form-label">Last Name*</label>
<input type="text" class="form-control" placeholder="" name="last_name" aria-label="Last name">
</div>
<!-- Phone number -->
<div class="col-md-6">
<label class="form-label">Phone number*</label>
<input type="text" class="form-control" placeholder="" name="phone_number" aria-label="Phone number">
</div>
<!-- Mobile number -->
<div class="col-md-6">
<label class="form-label">Mobile number*</label>
<input type="text" class="form-control" placeholder="" name="mobile_number" aria-label="Phone number">
</div>
<!-- Email -->
<div class="col-md-6">
<label for="inputEmail4" class="form-label">Email*</label>
<input type="email" class="form-control" id="inputEmail4" name="email_id">
</div>
<!-- Country -->
<div class="col-md-6">
<label class="form-label">Country*</label>
<select class="form-select" name="country">
<option value="">Select Country</option>
<?php if (!empty($countries)): ?>
<?php foreach ($countries as $country): ?>
<option value="<?php echo $country['country_id']; ?>">
<?php echo $country['country_name']; ?>
</option>
<?php endforeach; ?>
<?php endif;?>
</select>
</div>
<!-- State -->
<div class="col-md-6">
<label class="form-label">State*</label>
<select class="form-select" name="state">
<option selected>Select State</option>
<option value="1">State 1</option>
<option value="2">State 2</option>
<!-- Add more options as needed -->
</select>
</div>
<!-- City -->
<div class="col-md-6">
<label class="form-label">City*</label>
<select class="form-select" name="city">
<option selected>Select City</option>
<option value="1">City 1</option>
<option value="2">City 2</option>
<!-- Add more options as needed -->
</select>
</div>
</div> <!-- Row END -->
</div>
</div>
<!-- Upload profile -->
<div class="col-xxl-4">
<div class="bg-secondary-soft px-4 py-5 rounded">
<div class="row g-3">
<h4 class="mb-4 mt-0 fw-semibold">Upload your profile photo</h4>
<div class="text-center">
<!-- Image upload -->
<div class="square position-relative display-2 mb-3">
<!-- <i class="fas fa-fw fa-user position-absolute top-50 start-50 translate-middle text-secondary"></i> -->
</div>
<!-- Button -->
<input type="file" id="customFile" name="profile_image" hidden="">
<label class="btn btn-success-soft btn-block" for="customFile">Upload</label>
<button type="button" class="btn btn-danger-soft">Remove</button>
<!-- Content -->
</div>
</div>
</div>
</div>
</div> <!-- Row END -->
<!-- button -->
<div class="gap-3 d-flex justify-content-center text-center">
<button type="button" class="btn btn-danger">Delete profile</button>
<button type="submit" class="btn btn-custom">Update profile</button>
</div>
</div> <!-- Container END -->
</form> <!-- Form END -->
</body>
Countries_data.php – Model
<?php
class Countries_data extends CI_Model {
public function get_countries() {
$sql = "SELECT country_id, country_name FROM tbl_countries";
$query = $this->db->query($sql);
return $query->result_array();
}
}
?>
Countries.php – Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Countries extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Countries_data');
}
public function index() {
$data['countries'] = $this->Countries_data->get_countries();
$this->load->view('profile', $data);
}
}
?>
New contributor
Manish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.