Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PHP Journal Arman

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Arman Savsaiya

INDEX

NO DESCRIPTION PAGE NO
1 Create a form as given below. 2 To 4

2 Do Crud Operation (Insert, Update, Delete, Select) in Above Form. Data 4 To 7


will be shown as image given below. (Insert Minimum 10 record).

3 Data Should be shown City wise in Ascending Order in Above Form. 8

4 Data Should be shown Standard wise in Descending Order in Above Form. 8 To 9

5 Search Student data based on Name 9

1
Arman Savsaiya

Q-1 Create a form as given below.

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Admin</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous">

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>

</head>

<body>

<div class="container">

<div class="row">

<h1 class="text-center my-5">Welcome to Admin Dashboard</h1>

</div>

<div class="main">

<div class="row">

<form method="post" enctype="multipart/form-data">

<div>

<label class="form-label">Roll No:-</label>

<input type="text" class="form-control" name="rollno" placeholder="Roll No">

</div>

<div>

<label class="form-label">Student Name:-</label>

<input type="text" class="form-control" name="name" placeholder="Student Name">

</div>

2
Arman Savsaiya

<div>

<label class="form-label">City:-</label>

<input type="text" class="form-control" name="city" placeholder="City">

</div>

<div>

<label class="form-label">Parents Contact No:-</label>

<input type="text" class="form-control" name="p_contact" placeholder="Parents Contact No">

</div>

<div>

<label class="form-label">Standard:-</label>

<input type="text" class="form-control" name="standard" placeholder="Standard">

</div>

<div>

<label class="form-label">Upload File:-</label>

<input type="file" class="form-control" name="file">

</div>

<input type="submit" name="submit" class="btn btn-outline-success mt-5 w-100">

</div>

</form>

</div>

</div>

</body>

</html>

3
Arman Savsaiya

Q-2 Do Crud Operation (Insert, Update, Delete, Select) in Above Form. Data
will be shown as image given below. (Insert Minimum 10 record).
Ans:--
• Connect.php
<?php
error_reporting(0);
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "student";

$conn = new mysqli($servername,$username,$password,$dbname);


//print_r($conn);

if ($conn->connect_error) {
die("error is :".$conn->connect_error);
}
else{
//echo "connect succesfull";
}
?>
• Insert
<?php
require_once('connect.php');

4
Arman Savsaiya

if(isset($_POST['submit']))
{
// print_r($_POST);
// exit();
//print_r($_FILES);

$rollno=$_POST['rollno'];
$name=$_POST['name'];
$city=$_POST['city'];
$contact=$_POST['p_contact'];
$standard=$_POST['standard'];

$new_path = "upload/".$_FILES['file']['name'];
$old_path = $_FILES['file']['tmp_name'];
move_uploaded_file($old_path,$new_path);

$file = $_FILES['file']['name'];
if ($rollno && $name && $city && $contact && $standard && $file !== "")
{

$sql="INSERT INTO student_data (rollno,name,city,p_contact,standard,file)


VALUES ('$rollno','$name','$city','$contact','$standard','$new_path')";
$ans=$conn->query($sql);

if($ans == 1)
{
header('location:dashboard.php');
}
else
{
echo "error";
}
}
else
{
echo "Some filed Empty";
}
}

?>

• Update
<?php
require_once('connect.php');
$id = $_GET['up'];

5
Arman Savsaiya

$sql = "SELECT * FROM student_data WHERE id = $id";


$ans = $conn->query($sql);
$row = $ans -> fetch_object();

if(isset($_POST['update']))
{
$rollno=$_POST['rollno'];
$name=$_POST['name'];
$city=$_POST['city'];
$contact=$_POST['p_contact'];
$standard=$_POST['standard'];

if ($_FILES['file']['name'] && $_FILES['file']['tmp_name'] !== "")


{
$target = "upload/".$_FILES['file']['name'];
$old_path = $_FILES['file']['tmp_name'];
move_uploaded_file($old_path,$target);
}
else
{
$target = $_POST['default_path'];
}

$sql = "UPDATE student_data SET rollno= '$rollno' ,name= '$name',city=


'$city',p_contact= '$contact',standard= '$standard',file= '$target' WHERE id = $id";

$ans = $conn->query($sql);

if($ans == 1)
{
// echo "succesfully data Updated.";
header('location:dashboard.php');
}
else{
echo 'error';
}
}
?>
• Delete
if(isset($_GET['del']))
{
$delete = $_GET['del'];

$sql = "DELETE FROM student_data WHERE id = $delete";


//echo $sql;
$ans = $conn->query($sql);
if($ans == 1)

6
Arman Savsaiya

{
echo "succesfully data deleted.";
header('location:index.php');

else{
echo 'deleted not';
}
}

Q-3 Data Should be shown City wise in Ascending Order in Above Form.
Ans:-
$display = "SELECT * FROM student_data ORDER BY city ASC";

$result = $conn->query($display);

7
Arman Savsaiya

Q-4 Data Should be shown Standard wise in Descending Order in Above


Form.
Ans:- $display = "SELECT * FROM student_data ORDER BY standard DESC;";

$result = $conn->query($display);

Q-5 Search Student data based on Name


Ans:--
<?php

$roll2=$_POST["roll"];

if(isset($_POST["search"])){

$qur="SELECT * FROM student_data Where roll_no = '$roll2'";

$result= mysqli_query($con,$qur);

foreach($result as $row){

?>

<tr>

<td> <?php echo $row['roll_no']; ?> </td>

<td> <?php echo $row['name']; ?> </td>

<td> <?php echo $row['city']; ?> </td>

<td> <?php echo $row['P-contact']; ?> </td>

<td> <?php echo $row['standard']; ?> </td>

</tr>

8
Arman Savsaiya

<?php

$roll2=$_POST["roll"];

if(isset($_POST["Show"])){

$qur="SELECT * FROM student_data";

$result= mysqli_query($con,$qur);

foreach($result as $row){

?>

<tr>

<td> <?php echo $row['roll_no']; ?> </td>

<td> <?php echo $row['name']; ?> </td>

<td> <?php echo $row['city']; ?> </td>

<td> <?php echo $row['contact']; ?> </td>

<td> <?php echo $row['standard']; ?> </td>

</tr>

<?php

?>

</table>

9
Arman Savsaiya

10

You might also like