-
Notifications
You must be signed in to change notification settings - Fork 5
/
insert.php
51 lines (43 loc) · 1.58 KB
/
insert.php
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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "DBMS";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->beginTransaction();
$conn->exec("INSERT INTO STUDENT (STU_ID, F_NAME, L_Name, FATHER_NAME, DOB,
BRANCH, CGPA, MESS_ID, HOSTEL_ID, ROOM_NO)
VALUES ('$_POST[sid]','$_POST[fname]','$_POST[lname]','$_POST[father]',
'$_POST[dob]','$_POST[branch]','$_POST[cgpa]','$_POST[mess]',
'$_POST[hostel]','$_POST[room]')");
$conn->commit();
echo "<table style='border: solid 1px black;'>";
echo "<tr><th>Id</th><th>Firstname</th><th>Lastname</th><th>FATHER'S NAME</th><th>DOB</th><th>BRANCH</th><th>CGPA</th><th>HOSTEL ID</th><th>MESS ID</th><th>ROOM NO</th></tr>";
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width: 150px; border: 1px solid black;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "\n";
}
} $stmt = $conn->prepare("SELECT * FROM STUDENT");
$stmt->execute();
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
$conn = null;
?>