Postingan lainnya
Input data boolean ke database dengan php
saya bingung cara ngisi data yang tipe datanya itu boolean di postgre, saya punya tabel yg berisi field namanya is_male. nanti saat ngisi form di browser jika yang ngisi cowok brarti data yang masuk cowok di databasenya di centang , kalo cewek berarti uncentang
if ($selected_radio == 'male') {
$male_status = TRUE;
}
else if ($selected_radio == 'female') {
$female_status = FALSE;
}
if($errMsg == ''){
try {
$stmt = $db->prepare('INSERT INTO sso.users ( username, password, full_name, is_male,
email, phone, company, job_position, address, is_verified)VALUES
(:username, :password, :full_name, :gender, :email, :phone, :company,
:job_position, :address, :is_verified);');
$stmt->execute(array(
':username' => $username,
':password' => $password,
':full_name' => $full_name,
':gender' => $selected_radio,
':email' => $email,
':phone' => $phone,
':company' => $company,
':job_position' => $job_position,
':address' => $address,
':is_verified' => FALSE
));
mohon koreksinya,
2 Jawaban:
ini dijadikan satu saja <pre> if ($selected_radio == 'male') { $status = TRUE; } else { $status = FALSE; } // diquerynya ditambahkan ':is_male' => $status </pre> btw bedanya gender sama is_male apa ya?
@dianarifr kalo gini waktu datanya false muncul Fatal error: Uncaught PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type boolean: "" .kalo datanya true bisa, coba pake kode yg diatas sama error nya <pre> if(isset($_POST['submit'])) { if(isset($_POST['IsMale']) && $_POST['IsMale'] == 'true') $_POST['IsMale'] = TRUE;
else $_POST['IsMale'] = FALSE; </pre>