· 5 years ago · Mar 05, 2020, 06:14 AM
1<?php
2
3$link = mysql_connect("localhost", "root", "");
4mysql_select_db("student_info", $link);
5
6/********************************* Add Student Info ************************************/
7
8 $firstname = $_POST["firstname"];
9 $lastname = $_POST["lastname"];
10 $stdroll = $_POST["stdroll"];
11 $address= $_POST["address"];
12 $email = $_POST["email"];
13 $sex = $_POST["sex"];
14 $c1 = $_POST["c1"];
15 $c2 = $_POST["c2"];
16 $dept=$_POST["dept"];
17 $session = $_POST["session"];
18 $submark=$_POST["submark"];
19
20
21
22 if( !empty($firstname) ){
23 $query = "INSERT INTO information
24 SET first_name = '{$firstname}',
25 last_name = '{$lastname}',
26 stdroll = '{$stdroll}',
27 address = '{$address}',
28 email = '{$email}',
29 sex = '{$sex}',
30 optional_1 = '{$c1}',
31 optional_2 = '{$c2}',
32 dept = '{$dept}',
33 session = '{$session}',
34 submark='{$submark}'";
35
36 $result = mysql_query($query, $link) or die( "Error in insertion: ".mysql_error());
37 echo "<script>window.alert('Added succsessfully');</script>";
38 echo "<script>window.location='home.php';</script>";
39 }
40 echo "<script>window.location='home.php';</script>";
41 ?>
42
43
44
45
46<!DOCTYPE html>
47<html>
48<head>
49<title>Lab 3(b)</title>
50
51<!-- CCS part -->
52<link rel="stylesheet" type="text/css" href="style.css" />
53</head>
54<body >
55
56<form action="add_process.php" method="post" id="form">
57<fieldset>
58 <legend style="background-position:center">Students Details </legend>
59 <p class="left"> <a href="show.php"> Show </a></p>
60 <p><label>*First name: <input type="text" name="firstname" required> </label></p>
61 <p><label>Last name: <input type="text" name="lastname" ></label></p>
62 <p><label>*Student Roll: <input type="text" name="stdroll" required></label></p>
63 <p> <label class="address_field">*Address: <textarea rows="7" cols="50"placeholder="Adress goes here..." name="address" required></textarea></label>
64 </p>
65 <p><label for="email">*Email address: </label> <input type="text" name="email" id="email" size="20" maxlength="50" required /></p>
66 <p>*Sex:<br><input type="radio" name="sex" value="male" required>Male<br>
67 <input type="radio" name="sex" value="female"required>Female</p>
68 <p>*Department:<select name="dept" required>
69 <option></option>
70 <option value="CSE">CSE</option>
71 <option value="ECE">ECE</option>
72 <option value="BBA">BBA</option>
73 </select></p>
74 <p><label>*Session: <input type="text" name="session" required></label></p>
75 <p>Have:<br><input type="checkbox" name="c1" value="laptop">Laptop<br>
76 <input type="checkbox" name="c2" value="desktop">Desktop<br></p>
77 <p>*Subject Marks:<input type="text" name="submark" size="20" placeholder="Subject Marks" required> </p><br><br>
78
79 <button type="reset" value="reset"> Clear </button>
80 <button type="submit" value="submit"> Submit </button>
81</fieldset>
82</form>
83
84</body>
85</html>
86
87
88
89
90
91
92
93<html>
94<?php
95//$thishost="localhost";
96//$dbuser="root";
97//$dbpassword="";
98//$database="student_info";
99//$conn=mysqli_connect($thishost,$dbuser,$dbpassword,$database);
100//if (!$conn) {
101 //echo "Error: Unable to connect to MySQL." . PHP_EOL;
102 $link = mysql_connect("localhost", "root", "","student_info");
103 mysql_select_db("student_info");
104
105 function calculate_gpa($m){
106 if($m <= 39){
107 $gpa = "F";}
108 elseif($m <= 44){
109 $gpa = "D";}
110 elseif($m <= 49){
111 $gpa = "C";}
112 elseif($m <= 54){
113 $gpa = "C+";}
114 elseif($m <= 59){
115 $gpa = "B-";}
116 elseif($m <= 64){
117 $gpa = "B";}
118 elseif($m <= 69){
119 $gpa = "B+";}
120 elseif($m <= 74){
121 $gpa = "A-";}
122 elseif($m <= 79){
123 $gpa = "A";}
124 elseif($m <= 100){
125 $gpa = "A+";}
126
127 return $gpa;
128}
129 $query = "SELECT * FROM information i";
130 $result = mysql_query($query) or die( "Error in: ".mysql_error());
131 $num = mysql_num_rows($result);
132 //echo $num;
133 ?>
134 <center>
135 <table widtd="200" border="1" cellspacing="1" cellpadding="1">
136
137
138 <tr>
139
140 <th>FIrst Name</th>
141 <th>Last Name</th>
142 <th>Student Roll</th>
143 <th>Address</th>
144 <th>E-mail</th>
145 <th>Sex</th>
146 <th>Extra have 1</th>
147 <th>Extra have 1</th>
148 <th>Department</th>
149 <th>Session</th>
150 <th>Grade</th>
151 </tr>
152
153 <tr>
154 <?php while($row = mysql_fetch_array($result)){ ?>
155
156 <td><?php echo $row[0];?> </td>
157 <td><?php echo $row[1];?> </td>
158 <td><?php echo $row[2];?> </td>
159 <td><?php echo $row[3];?> </td>
160 <td><?php echo $row[4];?> </td>
161 <td><?php echo $row[5];?> </td>
162 <td><?php if($row[6]) echo $row[6]; else echo "X"; ?> </td>
163 <td><?php if($row[7]) echo $row[7]; else echo "X"; ?> </td>
164 <td><?php echo $row[8];?> </td>
165 <td><?php echo $row[9];?> </td>
166 <td><?php echo calculate_gpa($row[10]);?> </td>
167 </tr>
168
169<?php } ?>
170
171
172</table>
173</center>
174</html>
175
176
177
178
179
180
181
182
183CREATE DATABASE IF NOT EXISTS student_information;
184USE student_information;
185
186
187DROP TABLE IF EXISTS `information`;
188CREATE TABLE `information` (
189 `first_name` varchar(45) NOT NULL,
190 `last_name` varchar(45) DEFAULT NULL,
191 `stdroll` int(10) unsigned NOT NULL,
192 `address` varchar(45) DEFAULT NULL,
193 `email` varchar(45) DEFAULT NULL,
194 `sex` varchar(10) DEFAULT NULL,
195 `optional_1` varchar(10) DEFAULT NULL,
196 `optional_2` varchar(10) DEFAULT NULL,
197 `dept` varchar(10) DEFAULT NULL,
198 `session` varchar(10) DEFAULT NULL,
199 `submark` int(10) unsigned NOT NULL,
200 PRIMARY KEY (`stdroll`)
201) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
202
203
204
205
206
207
208
209#form {
210 width:50%;
211 height:auto;
212 text-align:left;
213 padding:30px;
214}
215.left {
216 float:right;
217}
218.address_field {
219 vertical-align:top;
220}