I'm building a delivery website.
If you have an account,for delivery details you have 2 options:
- Use the account delivery details(you complete them when you register),
- Use different delivery details(you complete them in shopping cart)
I'm making these verifications:
The user is logged in? If yes, verify if he entered some new delivery details(i'm using POST to take the values and i'm making an array with them-$data_pos).If he entered, so empty($data_pos) will be false, make a new array with his name(from account) and the total price and insert the order in database.
If the user is not logged in, he will need to complete the details to proceed.
The problem is that,even if $data_pos(the delivery details that he can complete to overwrite the account delivery details) is empty or not, the function empty always goes on false so even if he enters nothing, it will say that he entered something.
Note: This it's a function i made to print_r an array and die.Just debugging purpose.
echo '<pre>';
print_r($data);
die();
Model:
if($this->session->userdata('logged_in')){
$data_pos = array(
'telephone' => $this->input->post('phone_pos'),
'address' => $this->input->post('address_pos'),
'details' => $this->input->post('details'),
);
if(empty($data_pos) == false){
$data = array(
'client_name' => $this->session->userdata('email'),
'telephone' => $this->input->post('phone_pos'),
'address' => $this->input->post('address_pos'),
'details' => $this->input->post('details'),
'price' => $this->cart->total(),
);
echo '<pre>';
print_r($data_pos);
echo 'second array is not empty';
die("\n".'die in '. __FILE__ . ' at line '. __LINE__);
}else{
$data = array(
'client_name' => $this->session->userdata('email'),
'telephone' => $this->session->userdata('phone'),
'address' => $this->session->userdata('address'),
'details' => $this->input->post('details'),
'price' => $this->cart->total(),
);
echo '<pre>';
print_r($data);
echo 'i take informations from account beacuse the second array is empty';
die("\n".'die in '. __FILE__ . ' at line '. __LINE__);
}
}