<div class="container"> <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method = "POST"> <table class="table table-hover"> <thead> <tr style="background-color: cadetblue;"> <th>STUDENT ID</th> <th>LAST NAME</th> <th>FIRST NAME</th> <th>DATE ENROLLED</th> <th>ACTIONS</th> </tr> <tr> <?php { $qry = mysql_query("INSERT INTO students (stud_id, last_name, first_name, date_enrol) VALUES ('$stud_id','$last_name','$first_name','$date_enrol')"); } echo "<tr>"; echo "<th><input type = 'text' name = 'stud_id' placeholder = 'Student ID'></th>"; echo "<th><input type = 'text' name = 'last_name' placeholder = 'Last Name'></th>"; echo "<th><input type = 'text' name = 'first_name' placeholder = 'First Name'></th>"; echo "<th><input type = 'text' name = 'date_enrol' placeholder = 'Date Enrolled'></th>"; echo "<th><input type = 'submit' name = 'submit' class='btn btn-primary' value='Add Student'></th>"; echo "</tr>"; echo "<tr class='record'>"; echo "<td>". $row['stud_id'] ."</td>"; echo "<td>". $row['last_name'] ."</td>"; echo "<td>". $row['first_name'] ."</td>"; echo "<td>". $row['date_enrol'] ."</td>"; echo '<td><a href="#" id="'.$row['id'].'" class="delbutton" title="Click To Delete"><h1 class="btn btn-primary">Delete</h1></a></td>'; echo "</tr>"; } ?> </tr> </tbody> </table> </form> </div> <script src="js/jquery.js"></script> <script type="text/javascript"> $(function() { $(".delbutton").click(function(){ var element = $(this); var del_id = element.attr("id"); var info = 'id=' + del_id; if(confirm("Are you sure do you want to delete this data? There is NO undo!")) { $.ajax({ type: "GET", url: "delete.php", data: info, success: function(){ } }); $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast") .animate({ opacity: "hide" }, "slow"); } return false; }); }); </script>
<?php include('dbcon.php'); if($_GET['id']) { $id = $_GET['id']; $sql_delete = "DELETE FROM students WHERE id ='$id'"; } ?>
<?php $mysql_hostname = "localhost"; $mysql_user = "root"; $mysql_password = ""; $mysql_database = "data"; $con = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die ("Please Check Your Database Connection."); ?>