Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 20

EXP NO: 6 DATABASE APPLICATIONS USING PHP AND MYSQL

 
AIM: To create a simple program for database applications using PHP and MYSQL

PROCEDURE:
Step 1: Open the Xampp control and start Apache and MySql.
Step 2: Open the browser and type localhost to check the web server is running.
Step 3: Choose phpmyadmin option select database->Create database->Create.
Step 4: Create table under the new database created with number of rows->press go.
Step 5: Give name of the column or attribute and data type with size->press save.
Step 6: Insert rows one by one->press go.
Step 7: Type the program in note pad, save and run in browser.
Index.html:
<!DOCTYPE html>
<body bgcolor="#bbffa0">
<center>
<br>
<h1>Database Application<h1>
<h3>You can Insert, delete and search your data</h3>
<a href="insert.php">Insert</a>
<br>
<br>
<a href="delete.php">Delete</a>
<br>
<br>
</center>
<body>
Insert.php:

<!doctype html>
<body bgcolor="#aacb00">
<form method="POST" action="insert_process.php">
<center>
<h1>Insert your Details here</h1>
<h2>
Name:
<br><input type="text" name="name">
<br>
<br>
Register Number:
<br><input type="text" name="reg">
<br>
<br>
Age:
<br> <input type="text" name="age">
<br>
<br>
<br>
<input type="submit" value="Insert" name="insert">
<br>
<br>
</h2>
</center>
</form>
</body>
Insert_process.php
</html>
<?php
// Create connection
$conn = mysqli_connect("localhost","root","","itessentials"); // Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$name=$_POST['name'];
$regno=$_POST['reg'];
$age=$_POST['age'];
$sql = "INSERT INTO student (name, reg_no, age)VALUES
(‘$name','$regno','$age')";
if ($conn->query($sql) === TRUE) {
echo "Inserted successfully";
}
?>
Delete.php:
<!DOCTYPE html>
<body bgcolor="#bbccf0">
<br>
<center>
<h1>Delete Your Data</h1><h2>
<form method="POST" action="del_process.php">
Enter the Register no :<input type="text" name="reg">
<br>
<br>
<input type="submit" value="DeleteData"></h2>
</center> </form> </body> </html>
Del_process.php:
<?php
$conn = mysqli_connect("localhost","root","","itessentials");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$regno=$_POST["reg"];
$sql = "DELETE FROM student WHERE reg_no=$regno";
//$result = mysqli_query($conn,$sql);
if ($conn->query($sql) === TRUE) {
echo "Record Deleted successfully";
}
?>
EXP.NO: 7 Student Information Retrieval System Using PHP and MYSQL
 
AIM: To retrieve Student information using PHP and Mysql.
 
PROCEDURE:
1. Create a form and add a text box into it to get the input (Register Number).
2. Create Mysql database with required attributes of student.
3. Use table tags for the alignment of student attributes.
4. Use Select Query to retrieve the student information.
5. Give the Register number of the student in the text box and press "Get Info"
button to retrieve the student details.
PROGRAM:
dd.html
<html>
<body>
<form class="" action="index2.php" method="get">
<h1>Get Student Info</h1>
<input type="text" name="reg_no" value="" placeholder="Register Number">
<button type="submit">Get Info</button>
</form>
</body>
</html>
index2.php
<?php
if(isset($_GET["reg_no"]) && $_GET["reg_no"]!=''){
$reg_no = $_GET["reg_no"];
$conn = mysqli_connect("localhost","root","","tt");
$sql = "select * from students where reg_no=$reg_no";
$result = mysqli_query($conn,$sql);
if(mysqli_num_rows($result)>0){
?>
<center>
<thead>
<tr > Student Info</th> </tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_assoc($result)){
?>
<tr> <td>Student Name</td>
<td> <?php echo $row["student_name"]; ?></td> </tr>
<tr> <td>Reg No</td>
<td><?php echo $row["reg_no"]; ?> </td> </tr>
<tr> <td> Department</td>
<td><?php echo $row["department"]; ?> </td> </tr>
<tr>
<td> Batch </td>
<td> <?php echo $row["batch"]; ?></td> </tr>
<tr> <td> Father's Name </td> <td> <?php echo
$row["father_name"]; ?> </td> </tr>
<tr> <td> Mother's Name </td>
<td> <?php echo $row["mother_name"]; ?> </td> </tr>
<?php
}
?>
</tbody>
</table> </center>
<?php
}
else {
echo "no record found";
}
} else
{
echo "Please enter some number";
}
?>

You might also like