Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
$data = [
                'name' => htmlspecialchars($this->input->post('name', true)),
                'email' => htmlspecialchars($email),
                'password' => password_hash($this->input->post('password1'), PASSWORD_DEFAULT),
                if ($status == 'Peserta') {
                    'role_id' => 6,
                } else if ($status == 'Pengurus') {
                    'role_id' => 5,
                } else {
                    'role_id' => 2,
                }
                'is_active' => 0,
                'date_created' => time()
            ];


What I have tried:

saya sudah mencoba menggantinya dengan T-IF tapi tetap error.
Posted
Updated 15-Jan-23 23:16pm
Comments
Richard MacCutchan 14-Jan-23 5:23am    
Where is the code that the error refers to?
Luc Pattyn 14-Jan-23 16:41pm    
I have no experience with CodeIgniter, however the commas near your if statements seem very odd, probably causing the second if to emit the error you're getting.

I would remove the commas after the constants 6/5/2 and add one after the last }

1 solution

You cannot put an if block inside an array declaration. You need to extract that part:
PHP
if ($status == 'Peserta') {
    $role_id = 6;
} else if ($status == 'Pengurus') {
    $role_id = 5;
} else {
    $role_id = 2;
}

$data = [
    'name' => htmlspecialchars($this->input->post('name', true)),
    'email' => htmlspecialchars($email),
    'password' => password_hash($this->input->post('password1'), PASSWORD_DEFAULT),
    'role_id' => $role_id,
    'is_active' => 0,
    'date_created' => time()
];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900