0

first of all I don't speak English but I use the translator to be able to reach more people who can help me, my problem is what I will detail below

  • I need to update information whenever the ID exists
  • If it does not exist, you must insert the information

Not the same of other question...

class Minuta extends Conectar{
        public function insert_minuta($usu_run,$rn_lun,$rn_mar,$rn_mie,$rn_jue,$rn_vie){
            $conectar=parent::conexion();
            parent::set_names();
            $busqueda = "SELECT EXISTS (SELECT * FROM tp_rancho WHERE rn_run=$usu_run);";
            if ($busqueda==1){
                $sql = "UPDATE tp_rancho SET rn_fecapo = NOW(), rn_lun=?, rn_mar=?, rn_mie=?, rn_jue=?, rn_vie=? WHERE rn_run=?;";
                $sql=$conectar->prepare($sql);            
                $sql->bindValue(1, $rn_lun);
                $sql->bindValue(2, $rn_mar);
                $sql->bindValue(3, $rn_mie);
                $sql->bindValue(4, $rn_jue);
                $sql->bindValue(5, $rn_vie);
                $sql->bindValue(6, $usu_run); 
                $sql->execute();
                return $resultado=$sql->fetchAll();
            }else if ($busqueda==0){
                $sql = "INSERT INTO tp_rancho (rn_id, rn_run, rn_fecapo, rn_lun, rn_mar, rn_mie, rn_jue, rn_vie) VALUES (NULL, ?, NOW(), ?, ?, ?, ?, ?);";
                $sql=$conectar->prepare($sql);            
                $sql->bindValue(1, $usu_run);
                $sql->bindValue(2, $rn_lun);
                $sql->bindValue(3, $rn_mar);
                $sql->bindValue(4, $rn_mie);
                $sql->bindValue(5, $rn_jue);
                sql->bindValue(6, $rn_vie); 
                $sql->execute();
                return $resultado=$sql->fetchAll();                  
            }
                
        }
    }
4z0TE_
  • 1
  • 1

0 Answers0