false, // turn off emulation mode for "real" prepared statements PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, //turn on errors in the form of exceptions PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, //make the default fetch be an associative array ]; try { $pdo = new PDO($dsn, $db_user, $db_password, $options); } catch (Exception $e) { error_log($e->getMessage()); exit('Something weird happened'); //something a user can understand } $stmt = $pdo->prepare("UPDATE data_karyawan SET created=?,idrfid=?,nama=?,division=?,mail=?,alamat=?,picture=? WHERE id=?"); if(!$stmt->execute([ $created,$idrfid,$nama,$division,$mail,$alamat,$picture,$id ])) { echo "Something went wrong. Please try again later."; header("location: error.php"); } else{ $stmt = null; echo ''; } } else { // Check existence of id parameter before processing further if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){ // Get URL parameter $id = trim($_GET["id"]); // Prepare a select statement $sql = "SELECT * FROM data_karyawan WHERE id = ?"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "i", $param_id); // Set parameters $param_id = $id; // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ $result = mysqli_stmt_get_result($stmt); if(mysqli_num_rows($result) == 1){ /* Fetch result row as an associative array. Since the result set contains only one row, we don't need to use while loop */ $row = mysqli_fetch_array($result, MYSQLI_ASSOC); // Retrieve individual field value $created = $row["created"]; $idrfid = $row["idrfid"]; $nama = $row["nama"]; $division = $row["division"]; $mail = $row["mail"]; $alamat = $row["alamat"]; $picture = $row["picture"]; } else{ // URL doesn't contain valid id. Redirect to error page header("location: error.php"); exit(); } } else{ echo "Oops! Something went wrong. Please try again later."; } } // Close statement mysqli_stmt_close($stmt); // Close connection mysqli_close($link); } else{ // URL doesn't contain id parameter. Redirect to error page header("location: error.php"); exit(); } } ?>