I have a data insertion form, but when I insert the information I get these errors:
PHP error encountered
Severity: 8192
Message: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated
File: helpers/form_helper.php
Numéro de la ligne: 647
This error indicates that this field is empty when this is not the case.
When I fill out this field again, this time it is this message that appears.
Fatal error: Uncaught Error: Call to a member function row() on string in C:xampphtdocshopitalapplicationmodulespatientcontrollerspatient.php:361 Stack trace: #0 C:xampphtdocshopitalsystemcoreCodeIgniter.php(360): Patient->addNew() #1 C:xampphtdocshopitalindex.php(208): require_once(‘C:xampphtdocs…’) #2 {main} thrown in C:xampphtdocshopitalapplicationmodulespatientcontrollerspatient.php on line 361.
here is the code of the form in the view class
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><i class="fa fa-plus-circle"></i> <?php echo lang('register_new_patient'); ?></h4>
</div>
<div class="modal-body">
<form role="form" action="patient/addNew" method="post" enctype="multipart/form-data">
<div class="form-group">
<div class="col-md-12">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="col-md-3 payment_label">
<label for="exampleInputEmail1"><?php echo lang('doctor'); ?></label>
</div>
<div class="col-md-9">
<select class="form-control m-bot15 js-example-basic-multiple" multiple="" name="doctor[]" value=''>
<option value=""> </option>
<?php foreach ($doctors as $doctor) { ?>
<option value="<?php echo $doctor->id; ?>"><?php echo $doctor->name; ?> </option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-3"></div>
</div>
</div>
<div class="form-group">
<label for="exampleInputEmail1"><?php echo lang('name'); ?></label>
<input type="text" class="form-control" name="name" id="exampleInputEmail1" value='' placeholder="">
</div>
<div class="form-group">
<label for="exampleInputEmail1"><?php echo lang('password'); ?></label>
<input type="password" class="form-control" name="password" id="exampleInputEmail1" placeholder="">
</div>
<div class="form-group">
<label for="exampleInputEmail1"><?php echo lang('email'); ?></label>
<input type="text" class="form-control" name="email" id="exampleInputEmail1" value='' placeholder="">
</div>
<div class="form-group col-md-6 cat-container" data-id="Femme">
<label for="exampleInputEmail1"><?php echo lang('name_husband'); ?></label>
<input type="text" class="form-control" name="name_Us" id="nameUs" placeholder="">
<label for="exampleInputEmail1"><?php echo lang('number_pregnancy'); ?></label>
<input type="number" class="form-control" name="number_pregnancy" id="nbreEnfants" placeholder="">
</div>
<div class="form-group">
<label for="exampleInputEmail1"><?php echo lang('address'); ?></label>
<input type="text" class="form-control" name="address" id="exampleInputEmail1" value='' placeholder="">
</div>
<div class="form-group col-md-6">
<label for="exampleInputEmail1"><?php echo lang('andtecedentMed'); ?></label>
<input type="text" class="form-control" name="AntecedentMed" id="exampleInputEmail1" value='' placeholder="">
</div>
<div class="form-group col-md-6">
<label for="exampleInputEmail1"><?php echo lang('andtecedentFam'); ?></label>
<input type="text" class="form-control" name="AntecedentFam" id="exampleInputEmail1" value='' placeholder="">
</div>
<div class="form-group col-md-6">
<label for="exampleInputEmail1"><?php echo lang('taille'); ?></label>
<input type="text" class="form-control" name="taille" id="exampleInputEmail1" value='' placeholder="">
</div>
<div class="form-group col-md-6">
<label for="exampleInputEmail1"><?php echo lang('poids'); ?></label>
<input type="text" class="form-control" name="poids" id="exampleInputEmail1" value='' placeholder="">
</div>
<div class="form-group">
<label for="exampleInputEmail1"><?php echo lang('phone'); ?></label>
<input type="text" class="form-control" name="phone" id="exampleInputEmail1" value='' placeholder="">
</div>
<div class="form-group">
<label for="exampleInputEmail1"><?php echo lang('sex'); ?></label>
<select class="form-control m-bot15" name="sex" value=''>
<option value="Masculin" <?php
if (!empty($patient->sex)) {
if ($patient->sex == 'Masculin') {
echo 'selected';
}
}
?> > Masculin </option>
<option value="Féminin" <?php
if (!empty($patient->sex)) {
if ($patient->sex == 'Féminin') {
echo 'selected';
}
}
?> > Féminin </option>
<option value="Autres" <?php
if (!empty($patient->sex)) {
if ($patient->sex == 'Autres') {
echo 'selected';
}
}
?> > Autres </option>
</select>
</div>
<div class="form-group">
<label><?php echo lang('birth_date'); ?></label>
<input class="form-control form-control-inline input-medium default-date-picker" type="text" name="birthdate" value="" placeholder="">
</div>
<div class="form-group">
<label for="exampleInputEmail1"><?php echo lang('blood_group'); ?></label>
<select class="form-control m-bot15" name="bloodgroup" value=''>
<?php foreach ($groups as $group) { ?>
<option value="<?php echo $group->group; ?>" <?php
if (!empty($patient->bloodgroup)) {
if ($group->group == $patient->bloodgroup) {
echo 'selected';
}
}
?> > <?php echo $group->group; ?> </option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label for="exampleInputEmail1"><?php echo lang('image'); ?></label>
<input type="file" name="img_url">
</div>
<input type="hidden" name="id" value=''>
<input type="hidden" name="p_id" value='<?php
if (!empty($patient->patient_id)) {
echo $patient->patient_id;
}
?>'>
<section class="">
<button type="submit" name="submit" class="btn btn-info"><?php echo lang('submit'); ?></button>
</section>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
Here is the controller code:
public function addNew() {
$id = $this->input->post('id');
$name = $this->input->post('name');
$password = $this->input->post('password');
$name_husband = $this->input->post('name_husband');
$number_pregnancy = $this->input->post('nbreEnfants');
$email = $this->input->post('email');
$doctor = $this->input->post('doctor');
$address = $this->input->post('address');
$antecedentMed = $this->input->post('antecedentMed');
$antecedentFam = $this->input->post('antecedentFam');
$taille = $this->input->post('taille');
$poids = $this->input->post('poids');
$phone = $this->input->post('phone');
$sex = $this->input->post('sex');
$birthdate = $this->input->post('birthdate');
$bloodgroup = $this->input->post('bloodgroup');
$patient_id = $this->input->post('p_id');
if (empty($patient_id)) {
$patient_id = rand(10000, 1000000);
}
if ((empty($id))) {
$add_date = date('d/m/y');
} else {
$add_date = $this->db->get_where('patient', array('id' => $id))->row()->add_date;
}
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
// Validating Catégory Field
$this->form_validation->set_rules('category', 'Category', 'trim|min_length[2]|max_length[100]|xss_clean');
// Validating Name Field
$this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[2]|max_length[100]|xss_clean');
// Validating Password Field
if (empty($id)) {
$this->form_validation->set_rules('password', 'Password', 'trim|min_length[5]|max_length[100]|xss_clean');
}
// Validating husband_name Field
if (empty($id)) {
$this->form_validation->set_rules('name_husband', 'Name_husband', 'trim|min_length[3]|max_length[100]|xss_clean');
}
// Validating number_enfants Field
if (empty($id)) {
$this->form_validation->set_rules('number_pregnancy', 'Number_pregnancy', 'trim|min_length[1]|max_length[100]|xss_clean');
}
// Validating Email Field
$this->form_validation->set_rules('email', 'Email', 'trim|min_length[5]|max_length[100]|xss_clean');
// Validating Doctor Field
$this->form_validation->set_rules('doctor', 'Doctor', 'trim|min_length[2]|max_length[100]|xss_clean');
// Validating antécédents médicaux Field
$this->form_validation->set_rules('antecedentMed', 'AntecedentM', 'trim|required|min_length[2]|max_length[500]|xss_clean');
// Validating antécédents familiaux Field
$this->form_validation->set_rules('antecedentFam', 'AntecedentF', 'trim|required|min_length[2]|max_length[500]|xss_clean');
// Validating taille Field
$this->form_validation->set_rules('taille', 'Taille', 'trim|required|min_length[4]|max_length[500]|xss_clean');
// Validating poids Field
$this->form_validation->set_rules('poids', 'Poids', 'trim|required|min_length[2]|max_length[500]|xss_clean');
// Validating Address Field
$this->form_validation->set_rules('address', 'Address', 'trim|required|min_length[2]|max_length[500]|xss_clean');
// Validating Phone Field
$this->form_validation->set_rules('phone', 'Phone', 'trim|required|min_length[2]|max_length[50]|xss_clean');
// Validating Email Field
$this->form_validation->set_rules('sex', 'Sex', 'trim|required|min_length[2]|max_length[100]|xss_clean');
// Validating Address Field
$this->form_validation->set_rules('birthdate', 'Birth Date', 'trim|min_length[2]|max_length[500]|xss_clean');
// Validating Phone Field
$this->form_validation->set_rules('bloodgroup', 'Blood Group', 'trim|min_length[1]|max_length[10]|xss_clean');
if ($this->form_validation->run() == FALSE) {
if (!empty($id)) {
redirect("patient/editPatient?id=$id");
} else {
$data = array();
$data['doctors'] = $this->doctor_model->getDoctor();
$data['groups'] = $this->donor_model->getBloodBank();
$data['settings'] = $this->settings_model->getSettings();
$this->load->view('home/dashboard', $data); // just the header file
$this->load->view('add_new', $data);
$this->load->view('home/footer'); // just the header file
}
} else {
$file_name = $_FILES['img_url']['name'];
$file_name_pieces = explode('_', $file_name);
$new_file_name = '';
$count = 1;
foreach ($file_name_pieces as $piece) {
if ($count !== 1) {
$piece = ucfirst($piece);
}
$new_file_name .= $piece;
$count++;
}
$config = array(
'file_name' => $new_file_name,
'upload_path' => "./uploads/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => False,
'max_size' => "20480000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "1768",
'max_width' => "2024"
);
$this->load->library('Upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('img_url')) {
$path = $this->upload->data();
$img_url = "uploads/" . $path['file_name'];
$data = array();
$data = array(
'patient_id' => $patient_id,
'img_url' => $img_url,
'category' => $category,
'name' => $name,
'email' => $email,
'address' => $address,
'antecedentMed' => $antecedentMed,
'antecedentFam' => $antecedentFam,
'doctor' => $doctor,
'phone' => $phone,
'sex' => $sex,
'birthdate' => $birthdate,
'bloodgroup' => $bloodgroup,
'add_date' => $add_date
);
} else {
//$error = array('error' => $this->upload->display_errors());
$data = array();
$data = array(
'patient_id' => $patient_id,
'category' => $category,
'name' => $name,
'email' => $email,
'doctor' => $doctor,
'address' => $address,
'antecedentMed' => $antecedentMed,
'antecedentFam' => $antecedentFam,
'phone' => $phone,
'sex' => $sex,
'birthdate' => $birthdate,
'bloodgroup' => $bloodgroup,
'add_date' => $add_date
);
}
$username = $this->input->post('name');
if (empty($id)) { // Adding New Patient
if ($this->ion_auth->email_check($email)) {
$this->session->set_flashdata('feedback', 'Cette adresse email est déjà enregistré dans la base données');
redirect('patient/addNewView');
} else {
$dfg = 5;
$this->ion_auth->register($username, $password, $email, $dfg);
$user_id = $this->db->insert_id();
$ion_user_id = $this->db->get_where('users_groups', array('id' => $user_id))->row()->user_id;
$this->patient_model->insertPatient($data);
$patient_user_id = $this->db->insert_id();
$id_info = array('ion_user_id' => $ion_user_id);
$this->patient_model->updatePatient($patient_user_id, $id_info);
$this->session->set_flashdata('feedback', 'Ajouté');
}
} else { // Updating Patient
$ion_user_id = $this->db->get_where('patient', array('id' => $id))->row()->ion_user_id;
if (empty($password)) {
$password = $this->db->get_where('users', array('id' => $ion_user_id))->row()->password;
} else {
$password = $this->ion_auth_model->hash_password($password);
}
$this->patient_model->updateIonUser($username, $email, $password, $ion_user_id);
$this->patient_model->updatePatient($id, $data);
$this->session->set_flashdata('feedback', 'Modifié');
}
// Loading View
redirect('patient');
}
}
Finally, here is the model code:
class Patient_model extends CI_model {
function insertPatient($data) {
$data1 = array('hospital_id' => $this->session->userdata('hospital_id'));
$data2 = array_merge($data, $data1);
$this->db->insert('patient', $data2);
}
}
And this is the Line 361 wich is indicated as containing the error:
$ion_user_id = $ion_user_id->row()->id;