HTMLify
Create-some-new.php
Views: 737 | Author: djdj
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | <?php $add = false; $update = false; $delete = false; // Connecting to the Db $servername = "localhost"; $username = "root"; $password = ""; $database = "form"; //create connection $conn = mysqli_connect($servername, $username, $password, $database); if(!$conn){ die('Connection fail!!'.mysqli_connect_error()); } else{ //echo "Connection was successful"; } // echo $_POST['snoEdit']; // echo $_GET['update']; // exit(); if(isset($_GET['delete'])){ $sno = $_GET['delete']; $delete = true; $sql = "DELETE FROM `nodes` WHERE `sno` = '$sno' "; $result = mysqli_query($conn, $sql); //redirection header('refresh:1;url=http://localhost:3000/Create-some-new.php'); } if ($_SERVER['REQUEST_METHOD'] == 'POST'){ if (isset($_POST['snoEdit'])){ //Update the record $sno = $_POST['snoEdit']; $name = $_POST['nameEdit']; $title = $_POST['titleEdit']; $desc = $_POST['descEdit']; $sql = "UPDATE `nodes` SET `name` = '$name' , `title` = '$title' , `desc` = '$desc' WHERE `sno` = '$sno' "; $result = mysqli_query($conn, $sql); if($result){ // echo "<br>Record updated successfully"; $update = true; } // else{ // echo "<br>Record could not update"; // } } else{ $name = $_POST['name']; $title = $_POST['title']; $desc = $_POST['desc']; $sql = "INSERT INTO `nodes` (`name`, `title`, `desc`) VALUES ('$name', '$title', '$desc')"; $result = mysqli_query($conn, $sql); if($result){ $add = true; } } } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdn.datatables.net/2.0.1/css/dataTables.dataTables.min.css"> <title>Add Points/Tasks/Information</title> </head> <body> <div class="modal" id="editModal" tabindex="-1" role="dialog"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Update your Data</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <form action="" method="POST"> <div class="modal-body"> <input type="hidden" name="snoEdit" id="snoEdit"> <div class="form-group mt-3"> <label for="name">Name</label> <input type="text" class="form-control" id="nameEdit" name = "nameEdit" aria-describedby="emailHelp" placeholder="Enter your name" > </div> <div class="form-group"> <label for="title">Title</label> <input type="text" class="form-control" id="titleEdit" name = "titleEdit" aria-describedby="emailHelp" placeholder="Enter your title" > <!-- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> --> </div> <div class="form-group"> <label for="desc">Desc</label> <textarea rows="5" class="form-control" name = "descEdit" id="descEdit" placeholder="Enter your desc" ></textarea> </div> <!-- <div class="form-group form-check"> <input type="checkbox" class="form-check-input" id="exampleCheck1"> <label class="form-check-label" for="exampleCheck1">Check me out</label> </div> --> <!-- <button type="submit" class="btn btn-primary">Update</button> --> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="submit" class="btn btn-primary">Save changes</button> </div> </form> </div> </div> </div> <nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <a class="navbar-brand" href="">SabkaCode</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav mr-auto"> <li class="nav-item active"> <a class="nav-link" href="">Home <span class="sr-only">(current)</span></a> </li> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> More </a> <div class="dropdown-menu" aria-labelledby="navbarDropdown"> <a class="dropdown-item" href="http://htmlify.artizote.com">HTMLify</a> <!--<a class="dropdown-item" href="#"></a>--> <div class="dropdown-divider"></div> <a class="dropdown-item" href="#">Feedback</a> </div> </li> <li class="nav-item"> <a class="nav-link" href="https://github.com/upraity">Github</a> </li> <li class="nav-item"> <!--<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>--> </li> </ul> <form class="form-inline my-2 my-lg-0"> <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search"> <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button> </form> </div> </nav> <?php if($add){ echo ' <div class="alert alert-success alert-success fade show" role="alert"> <strong>Success!!</strong> Your data have been inserted successfully. <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> '; } if($update){ echo ' <div class="alert alert-success alert-success fade show" role="alert"> <strong>Success!!</strong> Your data have been updated successfully. <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> '; } if($delete){ echo ' <div class="alert alert-success alert-dismissible fade show" role="alert"> <strong>Success!</strong> Your data have been deleted successfully . <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> '; } ?> <div class="container mt-3"> <form action="" method="POST"> <h2>Add your Data</h2> <div class="form-group mt-3"> <label for="exampleInputEmail1">Name</label> <input type="text" class="form-control" id="exampleInputEmail1" name = "name" aria-describedby="emailHelp" placeholder="Enter your name" > </div> <div class="form-group"> <label for="exampleInputEmail1">Title</label> <input type="text" class="form-control" id="exampleInputEmail1" name = "title" aria-describedby="emailHelp" placeholder="Enter your title" > <!-- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> --> </div> <div class="form-group"> <label for="exampleInputPassword1">Desc</label> <textarea rows="5" class="form-control" name = "desc" id="exampleInputPassword1" placeholder="Enter your desc" ></textarea> </div> <!-- <div class="form-group form-check"> <input type="checkbox" class="form-check-input" id="exampleCheck1"> <label class="form-check-label" for="exampleCheck1">Check me out</label> </div> --> <button type="submit" class="btn btn-primary">Add</button> </form> <table style="width:100%;" class="table mt-5" id="myTable"> <thead> <tr> <th scope="col">Sno</th> <th scope="col">Name</th> <th scope="col">Title</th> <th scope="col">Description</th> <th scope="col">Date Time</th> <th scope="col">Action</th> </tr> </thead> <tbody> <?php $sql = "SELECT * FROM `nodes` "; $result = mysqli_query($conn, $sql); $sno = 0; while($row = mysqli_fetch_assoc($result)){ $sno++; echo ' <tr> <th scope="row">'.$sno.'</th> <td>'.$row['name'].'</td> <td>'.$row["title"].'</td> <td>'.$row["desc"].'</td> <td>'.$row["data-time"].'</td> <td><button id='.$row['sno'].' class="edit btn btn-sn btn-primary">Edit</button> <button id=d'.$row['sno'].' class="delete btn btn-sn btn-primary">Delete</button></td> </tr> '; } ?> </tbody> </table> </div> <hr> <!-- <script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"> </script> --> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> <script src="//cdn.datatables.net/2.0.0/js/dataTables.min.js"></script> <script> // $(document).ready( function () { // $('#myTable').DataTable(); // }) let table = new DataTable('#myTable'); </script> <script> edit = document.getElementsByClassName('edit'); Array.from(edit).forEach((element)=>{ element.addEventListener("click", (e)=>{ console.log("edit ", ); tr = e.target.parentNode.parentNode; name = tr.getElementsByTagName("td")[0].innerText; title = tr.getElementsByTagName("td")[1].innerText; desc = tr.getElementsByTagName("td")[2].innerText; console.log(name, title, desc); nameEdit.value = name; titleEdit.value = title; descEdit.value = desc; snoEdit.value = e.target.id; console.log(e.target.id); $('#editModal').modal('toggle'); }) }) delet = document.getElementsByClassName('delete'); Array.from(delet).forEach((element)=>{ element.addEventListener("click", (e)=>{ console.log("edit ", ); sno = e.target.id.substr(1,) // tr = e.target.parentNode.parentNode; // name = tr.getElementsByTagName("td")[0].innerText; // title = tr.getElementsByTagName("td")[1].innerText; // desc = tr.getElementsByTagName("td")[2].innerText; if(confirm("Are you sure you want to delete this data!")){ console.log("yes"); window.location = `?delete=${sno}`; } else{ console.log("no"); } // console.log(name, title, desc); // nameEdit.value = name; // titleEdit.value = title; // descEdit.value = desc; // snoEdit.value = e.target.id; // console.log(e.target.id); // $('#editModal').modal('toggle'); }) }) </script> </body> </html> |