Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update using modal and php

Tags:

php

get

crud

I'm doing a CRUD operation using php and bootstrap only. I'm currently stuck at update because I cant seem to send the $_GET['updateid'] to my modal.

This is my href's, the delete href is working but the update is not.

<a href="#myModal?updateid=<?php echo $row['sched_id'];?>" data-toggle="modal"  
              class="btn btn-warning" data-target="#myModal">Update</a>
<a href="home.php?deleteid=<?php echo $row['sched_id'];?>" class="btn btn-danger">Delete</a>

This php should take the updateid from the href and pass it to the updateStud() function

if(isset($_GET['updateid'])){
  $mupdate_id = $_GET['updateid'];

  if(isset($_POST['modal-submit'])){

    $msubj = $_POST['modalsubject'];
    $msect = $_POST['modalsection'];
    $mday = implode("", $_POST['modalday']);
    $mstrTime = $_POST['modalstarttime'];
    $mendTime = $_POST['modalendtime'];

    $auth_user->updateSchedule($msubj,$msect,$mday,$mstrTime,$mendTime,$mupdate_id);
    $schedRow = $auth_user->readSchedule();
  }
}

this is my function update that takes all the data and executes the query

public function updateSchedule($msubj,$msect,$mday,$mstrTime,$mendTime,$mupdate_id){
        $stmt = $this->conn->prepare("UPDATE `schedule`   
            SET `subject_db` = :msubj,
            `section_db` = :msect,
            `sched_day` = :mday,
            `start_time` = :mstrTime,
             `end_time` = :mendTime
            WHERE `sched_id` = :mupdate_id ");

        $stmt->bindparam(":msubj", $msubj);
        $stmt->bindparam(":msect", $msect);
        $stmt->bindparam(":mday", $mday);
        $stmt->bindparam(":mstrTime", $mstrTime);
        $stmt->bindparam(":mendTime", $mendTime);
        $stmt->bindparam(":mupdate_id", $mupdate_id);

        $stmt->execute();

        return $stmt;
    }
like image 919
Kent Abrio Avatar asked Nov 20 '22 05:11

Kent Abrio


1 Answers

You need to using this script to your modal.

<a data-toggle="modal" data-target="#modal-target" data-id="<?= $idyouwant ?>">Change</a>

You can fill your modal with html that you want via ajax/jquery like this javascript

$('#modal-target').on('show.bs.modal', function(ev){
    var modal = $(this);
    var link = $(ev.relatedTarget);
    var id = link.data('id');
    modal.find('.modal-body').load('yourserver/?param=' + id); // will load modal body that you want
}

then you can configure your script as well as you want.

like image 120
maulana satya Avatar answered Jan 16 '23 22:01

maulana satya