?php //get and pass value from 'searchForm.php' $id = ''; if(isset( $_GET['id'])) { $id = $_GET['id']; } //retrieve dbrecord to the form try{ //include db connection include "../php/dbconfig.php"; // Prepare, bind and execute $sql = "SELECT crscode,crsname,duration,_deptcode FROM tblcourse WHERE crscode = ?"; $stmt = $conn -> prepare ($sql); $stmt->bind_param("s", $id); $stmt->execute(); $stmt->bind_result($crscode, $crsname,$duration,$_deptcode); // Echo while ($stmt->fetch()) { echo "<pre>"; echo "Deptcode: $crscode\n"; echo "Deptname: $crsname\n"; echo "Deptcode: $duration\n"; echo "Deptname: $_deptcode\n"; } // Close $stmt -> close(); $conn -> close(); }catch(Exception $e){ //echo "<p>Caught exception: " . $e->getMessage() . "</p>"; } // Update Function function update(){ $ID = $GLOBALS['id']; // Store the value of varialble $id // include db connection include "../php/dbconfig.php"; // Prepare and bind $sql = "UPDATE tblcourse SET crsname = ?, duration = ?, _deptcode = ? WHERE crscode = ?"; $stmt = $conn -> prepare($sql); $stmt -> bind_param("ssss",$crsname,$duration,$_deptcode,$ID); // Set parameters $crsname = trim($_POST['txtcrsname']); $duration = trim($_POST['txtduration']); $_deptcode = trim($_POST['cbodept']); // Execute if($stmt -> execute()){ echo " window.alert('Record Updated!'); window.location='seaCrs.php'; "; }else{ echo "ERROR: Could not execute query:" . mysqli_error($conn); } // close $stmt -> close(); $conn -> close(); } $mssg = ""; include '../php/functions.php'; //button update if(isset($_POST['btnupdate'])){ if(empty($_POST['txtcrscode']) || empty($_POST['txtcrsname']) || empty($_POST['txtduration']) || empty($_POST['cbodept'])){ $GLOBALS['mssg'] = "Please fill up all fields!"; }else{ update(); //calling update function } } //btn cancel if (isset($_POST['btncancel'])){ redirect("seaCrs.php"); echo " window.location='searchDept.php'; "; } ?> <pre> <title> Update Course .form-con{ background-color: ; width: 100%; padding: 10px; text-align: left; } .txtbtn{ width: 100%; } <br><br><br><br> <div class="form-con"> <h2 class="admin-headertitle">UPDATE COURSE</h2> <h3>Course Code:</h3> <h3>Course Name:</h3> <h3>Duration:</h3> <h3>Department: </h3> prepare($sql); // Execute and fetch $stmt -> execute(); $result = $stmt -> get_result(); while($row = $result -> fetch_assoc()){ //echo "" .$row['deptcode'] .""; } // Close $stmt -> close(); $conn -> close();*/ ?> prepare($sql); // Execute and fetch $stmt -> execute(); $result = $stmt -> get_result(); while($row = $result -> fetch_assoc()) { ?> > <br><br> <br><br> <p style="color: rgba(255, 0, 0, 1); font-style: italic"> </p> </div>
error_reporting(E_ALL); ini_set('display_errors', 1);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)