-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.php
More file actions
142 lines (138 loc) · 3.31 KB
/
Copy pathadd.php
File metadata and controls
142 lines (138 loc) · 3.31 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
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
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<?php
$div=$_POST["Rollno"];
if($div < 60)
{
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ddb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
else
{
if(isset($_POST["options"]))
{
$option=$_POST["options"];
$rn=$_POST["Rollno"];
$n=$_POST["Name"];
$m=$_POST["Marks"];
$d='C';
if($rn==" "||$n==" "||$m==null)
{
echo '<script >
alert("Enter valid Details");
window.location = "add.html";
</script>
';
}
if($option==1)
{
$result = mysqli_query($conn,"SELECT * FROM studentd WHERE Rollno = '$rn'");
if($result->num_rows == 1)
{
echo'
<script>
alert("Roll number already exist");
window.location = "add.html";
</script>
';
}
else
{
echo "Inserted";
$sql="INSERT INTO studentd VALUES('$rn','$n','$m','$d')";
mysqli_query($conn,$sql);
}
}
if($option==3)
{
echo "DELETED";
$sql="DELETE FROM studentd where Rollno='$rn' ";
mysqli_query($conn,$sql);
}
if($option==2)
{
echo "UPDATED";
$sql="UPDATE `studentd` SET `Name` = '$n', `marks` = '$m' WHERE `studentd`.`Rollno` = '$rn'";
mysqli_query($conn,$sql);
}
}
}
$conn->close();
}
elseif($div < 121)
{
//$myPDO = new PDO('pgsql:host=localhost;dbname=DDB', 'postgres', '123456');
$link=pg_connect("host=localhost port=5432 dbname=ddb user=postgres password=123456");
if (!$link)
{
die('Error: Could not connect: ');
}
else
{
if(isset($_POST["options"]))
{
$option=$_POST["options"];
$rn=$_POST["Rollno"];
$n=$_POST["Name"];
$m=$_POST["Marks"];
$d='D';
if($rn==" "||$n==" "||$m==null)
{
echo '<script >
alert("Enter valid Details");
window.location = "add.html";
</script>
';
}
if($option==1)
{ $q="SELECT * FROM studentc WHERE Rollno='$rn'";
$result = pg_query($q);
if (pg_num_fields($result)==1)
{
echo'
<script >
alert("Roll number already exist");
window.location = "add.html";
</script>
';
}
else
{
echo "Inserted";
$query="INSERT INTO studentc(Rollno,Name,Marks,Div) VALUES('$rn','$n','$m','$d')" ;
$result = pg_query($query);
}
if($option==3)
{
echo "DELETED";
$query="DELETE FROM studentc WHERE Rollno ='$rn'" ;
$result = pg_query($query);
}
}
if($option==2)
{
echo "UPDATED";
$query= "UPDATE studentc SET Name='$n', Marks='$m',Div='$d' WHERE Rollno='$rn'";
$result = pg_query($query);
}
}
}
}
else
{
echo "enter valid roll number";
}
?>
</head>
</html>