-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstudserver.php
More file actions
56 lines (44 loc) · 1.38 KB
/
Copy pathstudserver.php
File metadata and controls
56 lines (44 loc) · 1.38 KB
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
<?php
//session_start();
$db = mysqli_connect('localhost', 'root', '', 'experiment');
if(!$db){
die("could not connect".mysql_error());
}
// initialize variables
$stud_name = "";
$group_no = "";
$id = 0;
$edit_state = false;
//insert
if (isset($_POST['save'])) {
$stud_name = $_POST['stud_name'];
$group_no = $_POST['group_no'];
$query = mysqli_query ($db, "INSERT INTO students (stud_name,group_no) VALUES ('".$stud_name."','".$group_no."')") ;
$_SESSION['msg'] ="Record has been added.";
//mysqli_query($db,$query);
if($query){
header('location: studrec.php'); //redirect to studrec.php
}else{
echo "NO DATA RECORD INSERTED";
}
exit();
}
//retrieve and display records
$results = mysqli_query($db, "SELECT * FROM students");
//update
if(isset($_POST['update'])){
$stud_name = $_POST['stud_name'];
$group_no = $_POST['group_no'];
$id = $_POST['id'];
$query = mysqli_query($db, "UPDATE students SET stud_name='".$stud_name."', group_no='".$group_no."' WHERE stud_id =".$id);
$_SESSION['msg'] = "Experiment record has been updated";
header('location:studrec.php');
}
//delete
if(isset($_GET['del'])){
$id = $_GET['del'];
mysqli_query($db,"DELETE FROM students WHERE stud_id=".$id);
$_SESSION['msg'] = "Experiment record has been deleted";
header('location:studrec.php');
}
?>