我尝试更新t_judul和mahasiswa上的i​​d_status并将我的数据保存在t_jadwal上,所以我尝试了此代码

SQL成功在t_judul上保存数据
但是sql2和sql3无法将id_status更新为表t_judul和mahasiswa中的54

我的模特

public function simpanjadwal($post,$id_judul){
        $id_judul          = $this->db->escape($post['id_judul']);
        $id_status          = $this->db->escape($post['id_status']);
        $judul          = $this->db->escape($post['judul']);
        $topik               = $this->db->escape($post['topik']);
        $nim               = $this->db->escape($post['nim']);
        $nama_awal               = $this->db->escape($post['nama_awal']);
        $nama_akhir               = $this->db->escape($post['nama_akhir']);
        $pbb1               = $this->db->escape($post['pbb1']);
        $pbb2               = $this->db->escape($post['pbb2']);
        $pgj1               = $this->db->escape($post['pgj1']);
        $pgj2           = $this->db->escape($post['pgj2']);
        $waktuujian           = $this->db->escape($post['waktuujian']);
        $tempatujian               = $this->db->escape($post['tempatujian']);

        $sql = $this->db->query("INSERT INTO t_jadwal (
                    id_judul,
                    id_status,
                    judul,
                    topik,
                    nim,
                    nama_awal,
                    nama_akhir,
                    pbb1,
                    pbb2,
                    pgj1,
                    pgj2,
                    waktuujian,
                    tempatujian
                )
                VALUES
                    (
                    $id_judul,
                    $id_status,
                    $judul,
                    $topik,
                    $nim,
                    $nama_awal,
                    $nama_akhir,
                    $pbb1,
                    $pbb2,
                    $pgj1,
                    $pgj2,
                    $waktuujian,
                    $tempatujian
                                        )");
        $sql2  = $this->db->query("UPDATE mahasiswa, t_judul SET mahasiswa.id_status = 54 WHERE t_judul.nim = mahasiswa.nim AND t_judul.id_judul = ".intval($id_judul));
        $sql3  = $this->db->query("UPDATE t_judul,mahasiswa SET t_judul.id_status = 54 WHERE t_judul.nim = mahasiswa.nim AND t_judul.id_judul = ".intval($id_judul));

        return TRUE;
        }


我的控制者

public function inputjadwalseminar($id_judul){
     $this->load->model("m_pkip");

     $data['list_judulseminar'] = $this->m_pkip->selectjudul($id_judul);
     $data['list_dosen'] = $this->m_pkip->load_dosen();
     if(isset($_POST['btnSimpanJadwal'])){
         $this->m_pkip->simpanjadwal($_POST, $id_judul);
         redirect("pkip");
     }
     $data['default'] = $this->m_pkip->get_default($id_judul);
     $this->load->view("pkip/v_inputjadwalseminar",$data);
 }


sql2和sql3查询无法更新t_judul和mahasiswa中的id_status,但数据成功保存在t_jadwal中

我试图对sql2和sql3进行vardump,结果是bool(true)bool(true)
我试图进行vardump id_judul并说string(4)“ 72” *注意72是id_judul

最佳答案

解决了我将代码更改为

$sql2  = $this->db->query("UPDATE mahasiswa, t_judul SET mahasiswa.id_status = 54 WHERE t_judul.nim = mahasiswa.nim AND t_judul.id_judul = $id_judul");

$sql3  = $this->db->query("UPDATE t_judul,mahasiswa SET t_judul.id_status = 54 WHERE t_judul.nim = mahasiswa.nim AND t_judul.id_judul = $id_judul");

关于php - 如何在2表中更新? (t_judul和mahasiswa中的id_status),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57237914/

10-09 17:02