I want to insert data to database if there is no data yet in my database, but when there is a data in my database I want update it instead
How to know if there is no data yet or there is already in database here is my php code I have tried countRow etc, but always returning undefined method
public function tambahCatatanDosenPA($no, $catatan, $semester) {
$stmt = $this->conn->prepare("SELECT * FROM catatan_dosenpa WHERE no_user_id = ?");
$stmt->bind_param("s", $no);
$stmt->execute();
$stmt->bind_result($no_isi, $no_user_id_isi, $catatan_isi, $semester_isi);
$list_catatan = array();
while ($stmt->fetch()) {
$temp = array();
$temp['no'] = $no_isi;
$temp['no_user_id'] = $no_user_id_isi;
$temp['catatan'] = $catatan_isi;
$temp['semester'] = $semester_isi;
array_push($list_catatan,$temp);
}
$stmt->close();
if ($list_catatan.count() = 0) {
$stmt = $this->conn->prepare("INSERT INTO catatan_dosenpa(no_user_id, catatan, semester) VALUES(?, ?, ?)");
$stmt->bind_param("sss",$no, $catatan, $semester);
$result = $stmt->execute();
$stmt->close();
return true;
} else {
$stmt = $this->conn->prepare("UPDATE catatan_dosenpa SET catatan = ? WHERE no_user_id = ? AND semester = ?");
$stmt->bind_param("sss", $catatan, $no, $semester);
$result = $stmt->execute();
$stmt->close();
return true;
}
}