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

Connectivity:: $con $con

Uploaded by

deshmukhe0611
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)
10 views

Connectivity:: $con $con

Uploaded by

deshmukhe0611
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/ 6

Connectivity:

<?php
$con=mysqli_connect('localhost','root','','student_info') or
die("connection failed : ".mysqli_connect_error());
if ($con) {
echo "Connection Established Successfully";
}
else{
echo "Connection Could not be Established. Some Error has occured";
}
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>

Home page:

<!DOCTYPE html>
<html>
<head>
<title>insert records</title>
</head>
<body>
<div class="row text-center">
<div class="container">
<h1>Insert Student Information</h1>
<form action="home_page.php" method="post">
<b> Roll Number : </b> <input type="text" name="Roll_Number"
placeholder="Enter Roll Number"><br><br>
<b> Student Name: </b><input type="text" name="Student_Name"
placeholder="Enter Student Name"><br><br>
<b> Class : </b><input type="text" name="Class"
placeholder="Enter Class Name (TE A or TE B)"><br><br>
<b> Subject : </b><input type="text" name="Subject"
placeholder="Enter Subject Name"><br><br>
<b> Marks Obtained : </b><input type="text" name="Marks"
placeholder="Enter Marks Obtained"><br><br>
<input type="submit" name="submit" value="Add Student
Record"><br><br>
</form>
<button><a href="show_record.php">Show Students Records</a></button>
</div>
</div>
</body>
</html>
<?php
error_reporting(0);
include 'db_connection.php';
if (isset($_POST['submit'])) {
$Roll_Number = $_POST['Roll_Number'];
$Student_Name = $_POST['Student_Name'];
$Class = $_POST['Class'];
$Subject = $_POST['Subject'];
$Marks = $_POST['Marks'];
$sql = "INSERT INTO `te_2023` VALUES
('$Roll_Number','$Student_Name','$Class','$Subject','$Marks')";
$data=mysqli_query($con,$sql);
if ($data) {
echo "Student Record Inserted Sucessfully";
}else
{
echo "Record Could not be inserted. Some Error Occured";
}
}
?>

Delete page:

<?php
include ('db_connection.php');
$id = $_GET['roll_no'];
$sql ="DELETE FROM `te_2023` WHERE Roll_No='$id'";
$data = mysqli_query($con,$sql);
if ($data) {
echo "deleted";
header('location:show_record.php');
}else
{
echo "error";
}
?>

Show record:

<!DOCTYPE html>
<html>
<head>
<title>show records</title>
</head>
<body>
<?php
include ('db_connection.php');
$sql ="select * from te_2023";
$data =mysqli_query($con,$sql);
$total=mysqli_num_rows($data);
if ($total=mysqli_num_rows($data)) {
?>
<table border="2">
<tr>
<th>Roll Number</th>
<th>Student Name</th>
<th>Class</th>
<th>Subject</th>
<th>Marks Obtained</th>
<th>Update Record</th>
<th>Delete Record</th>
</tr>
<?php
while ($result = mysqli_fetch_array($data)) {
echo "
<tr>
<td>".$result['Roll_No']."</td>
<td>".$result['Student_Name']."</td>
<td>".$result['Class']."</td>
<td>".$result['Subject']."</td>
<td>".$result['Marks_Obtained']."</td>
<td><a href='update_record.php?roll_no=$result[Roll_No]
& studentname=$result[Student_Name] & class=$result[Class] &
subject=$result[Subject] & marks=$result[Marks_Obtained]'> Update
</a></td>
<td><a href='delete_record.php?roll_no=$result[Roll_No]
'>Delete </a></td>
</tr>
";
}
}
else
{
echo "no record found";
}
?>
</table>
</body>
</html>

Update record:

<!DOCTYPE html>
<html>
<head>
<title>update</title>
</head>
<body>
<form action="" method="get">
<input type="text" name="roll_no" placeholder="Enter Roll Number"
value="<?php echo $_GET['roll_no']; ?>"><br><br>
<input type="text" name="studentname" placeholder="Enter Student
Name" value="<?php echo $_GET['studentname']; ?>" ><br><br>
<input type="text" name="class" placeholder="Enter Class" value="<?
php echo $_GET['class']; ?>"><br><br>
<input type="text" name="subject" placeholder="Enter Subject Name"
value="<?php echo $_GET['subject']; ?>"><br><br>
<input type="text" name="marks" placeholder="Enter Marks Obtained"
value="<?php echo $_GET['marks']; ?>"><br><br>
<input type="submit" name="submit" value="Update Record">
</form>
<?php
error_reporting(0);
include ('db_connection.php');

if ($_GET['submit'])
{
$roll_no = $_GET['roll_no'];
$studentname = $_GET['studentname'];
$class = $_GET['class'];
$subject = $_GET['subject'];
$marks = $_GET['marks'];
$sql="UPDATE te_2023 SET Roll_No='$roll_no' ,
Student_Name='$studentname', Class='$class' , Subject='$subject',
Marks_Obtained='$marks' WHERE Roll_No='$roll_no'";
$data=mysqli_query($con, $sql);
if ($data) {
echo "Record Updated Successfully";
header('location:show_record.php');
}
else{
echo "Record is not updated";
}
}
else
{
echo "Click on button to save the changes";
}
?>
</body>
</html>

OUTPUTS:

You might also like