php
php
13. Using PHP and SQL, create and validate a sample login form.
14. Using PHP and SQL, develop a program to accept student information viz.
Accession
name, regno, course, sem, marks in 3 subjects from a web page and store
the information
in a database and to calculate total and average and to display the results
with proper
headings.
<?php(11)
// Database credentials
$servername = "localhost";
$username = "your_username";
$password = "your_password";
// Create connection
// Check connection
if ($conn->connect_error) {
// Create database
} else {
$conn->close();
?>
<?php(12)
$email = your_email@example.com;
If (filter_var($email, FILTER_VALIDATE_EMAIL)) {
} else {
?>
<?php(13)
// Database credentials
$servername = “localhost”;
$username = “your_username”;
$password = “your_password”;
$dbname = “myDB”;
// Create connection
// Check connection
If ($conn->connect_error) {
If ($_SERVER[“REQUEST_METHOD”] == “POST”) {
$username = $_POST[“username”];
$password = $_POST[“password”];
$result = $conn->query($sql);
If ($result->num_rows > 0) {
$row = $result->fetch_assoc();
If ($password == $row[“password”]) {
} else {
}
} else {
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h2>Login</h2>
<label for=”username”>Username:</label>
<label for=”password”>Password:</label>
<button type=”submit”>Login</button>
</form>
</body>
</html>
-----_
_______
<?php(14)
$servername = “localhost”;
$username = “your_username”;
$password = “your_password”;
$dbname = “your_database_name”;
// Create connection
// Check connection
If ($conn->connect_error) {
If ($_SERVER[“REQUEST_METHOD”] == “POST”) {
$accession_name = $_POST[“accession_name”];
$regno = $_POST[“regno”];
$course = $_POST[“course”];
$sem = $_POST[“sem”];
$sub1 = $_POST[“sub1”];
$sub2 = $_POST[“sub2”];
$sub3 = $_POST[“sub3”];
} else {
FROM students”;
$result = $conn->query($sql);
If ($result->num_rows > 0) {
Echo “<table>”;
Echo “<tr><th>Accession
Name</th><th>Regno</th><th>Course</th><th>Sem</th><th>Sub1</t
h><th>Sub2</th><th>Sub3</th><th>Total</th><th>Average</th></
tr>”;
While($row = $result->fetch_assoc()) {
Echo “<tr>”;
Echo “</tr>”;
Echo “</table>”;
} else {
Echo “0 results”;
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>Student Information</title>
</head>
<body>
</form>
</body>
</html>
<?php(15)
$servername = “localhost”;
$username = “your_username”;
$password = “your_password”;
$dbname = “your_database_name”;
// Create connection
// Check connection
If ($conn->connect_error) {
If ($_SERVER[“REQUEST_METHOD”] == “POST”) {
$accession_no = $_POST[“accession_no”];
$name = $_POST[“name”];
$basic = $_POST[“basic”];
$sql = “INSERT INTO employees (accession_no, name, basic, da, hra, pf,
tax, gross, net_pay)
} else {
$sql = “SELECT accession_no, name, basic, da, hra, pf, tax, gross, net_pay
FROM employees”;
$result = $conn->query($sql);
If ($result->num_rows > 0) {
Echo “<table>”;
Echo “<tr><th>Accession
No</th><th>Name</th><th>Basic</th><th>DA</th><th>HRA</th><th
>PF</th><th>Tax</th><th>Gross</th><th>Net Pay</th></tr>”;
While($row = $result->fetch_assoc()) {
Echo “<tr>”;
Echo “</tr>”;
Echo “</table>”;
} else {
Echo “0 results”;
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>Employee Information</title>
</head>
<body>
</form>
</body>
</html>