0% found this document useful (0 votes)
98 views

Database Mini Project

This document discusses connecting a PHP registration form to a MySQL database. It includes HTML code for a registration form that collects a student's name, gender, student ID, phone number, and department ID. It then shows PHP code that connects to a MySQL database called "college" using the credentials "root" and retrieves the form data using the POST method. The PHP code prepares an SQL statement to insert the form data into a "student" table in the database and executes it, then closes the database connection. When complete, it displays a success message.

Uploaded by

srii21rohith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

Database Mini Project

This document discusses connecting a PHP registration form to a MySQL database. It includes HTML code for a registration form that collects a student's name, gender, student ID, phone number, and department ID. It then shows PHP code that connects to a MySQL database called "college" using the credentials "root" and retrieves the form data using the POST method. The PHP code prepares an SQL statement to insert the form data into a "student" table in the database and executes it, then closes the database connection. When complete, it displays a success message.

Uploaded by

srii21rohith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

EX.

NO: 11 DATABASE CONNECTIVITY USING PHP


DATE:

AIM:

PROGRAM:

HTML CODE:
<!DOCTYPE html>
<html>
<head>
<title>STUDENT Registration Page</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
</head>
<body style="background-image: url('crop.jpg');color:white;text-align:center;background-repeat:
no-repeat;background-size: cover;">
<div class="container">
<div class="row col-md-6 col-md-offset-3">
<div class="panel panel-primary">
<div class="panel-heading text-center" >
<h1>Registration Form</h1>
</div>
<div class="panel-body">
<form action="connect.php" method="post">
<table style="margin:20px auto;" >
<tr>
<div class="form-group">
<td><label for="firstName">Name</label></td><td>
<input
type="text"
class="form-control"
id="firstName"
name="firstName"
/></td></tr><tr><td>
<div class="form-group">
<label for="gender">Gender</label></td><td>
<div>
<label for="male" class="radio-inline"
><input
type="radio"
name="gender"
value="m"
id="male"

ROLL NO:2127220801058 PAGE NO:


/>Male</label
>
<label for="female" class="radio-inline"
><input
type="radio"
name="gender"
value="f"
id="female"
/>Female</label
>
<label for="others" class="radio-inline"
><input
type="radio"
name="gender"
value="o"
id="others"
/>Others</label
>
</div></td></tr>
</div><tr>
<div class="form-group">
<td><label for="text">Student_ID</label></td>
<td><input
type="text"
class="form-control"
id="s_id"
name="s_id"
/></td>
</div>
</td><tr>
<div class="form-group">
<td><label for="number">Phone Number</label></td>
<td><input
type="number"
class="form-control"
id="number"
name="number"
/></td></tr><tr>
<div class="form-group">
<td><label for="text">DEPT_ID</label></td>
<td><input
type="text"
class="form-control"
id="d_id"
name="d_id"
/></td>
</div></tr>
</div></table>

ROLL NO:2127220801058 PAGE NO:


<input type="submit" class="btn btn-primary" />
</form>

</div>

</div>
</div>
</div>

<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">


<div class="toast-header">

</div>
</body>
</html>

PHP CODE:

<?php
$firstName = $_POST['firstName'];
$gender = $_POST['gender'];
$s_id = $_POST['s_id'];

$number = $_POST['number'];
$D_id = $_POST['d_id'];

// Database connection
$conn = new mysqli('localhost','root','','college');
if($conn->connect_error){
echo "$conn->connect_error";
die("Connection Failed : ". $conn->connect_error);
} else {
$stmt = $conn->prepare("insert into student(Name, Gender, s_id, Ph_no, DEPT_id)
values(?, ?, ?, ?, ?)");
$stmt->bind_param("sssis", $firstName, $gender, $s_id, $number,$D_id);
$execval = $stmt->execute();
echo $execval;
echo "Registration successfully...";
$stmt->close();
$conn->close();
}
?>

OUTPUT:

ROLL NO:2127220801058 PAGE NO:


RESULT:

ROLL NO:2127220801058 PAGE NO:

You might also like