b) Write a PHP script to create student.xml file which contains student roll no, name, address, collegeand course. Print students detail of specific course in tabular format after accepting course as input.
Answers
Answer:
PHP
Explanation:
PHP program to show the student information
PHP
<html>
<h2>T4Tutorials.com</h2>
<h3>simple programm</h3>
<p>show output student name and roll number</p>
</html>
<?php
class student
{
public $name= 'ali';
public $rno=55;
}
$a = new student();
echo $a->name;
echo "<br>";
echo $a->rno;
echo "<br>";
$b = new student ();
echo $b->name;
echo "<br>";
echo $b->rno;
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<html>
<h2>T4Tutorials.com</h2>
<h3>simple programm</h3>
<p>show output student name and roll number</p>
</html>
<?php
class student
{
public $name= 'ali';
public $rno=55;
}
$a = new student();
echo $a->name;
echo "<br>";
echo $a->rno;
echo "<br>";
$b = new student ();
echo $b->name;
echo "<br>";
echo $b->rno;
?>
PHP program to show the student information with form values entered by the user
PHP
<html>
<h2>T4Tutorials.com</h2>
<h3>Form program</h3>
<p>show output student name and roll number</p>
</html>
<html>
<body>
<form method="post">
<p>Enter Name</p>
<input type="text" name="name" />
<p>Enter Roll number</p>
<input type="text" name="number" />
<input type="submit" name="submit" />
</form>
<?php
class student
{
public $name= 'ali';
public $rno=77;
}
$a = new student();
if(isset($_POST['submit'])){
$a->name=$_POST['name'];
$a->rno=$_POST['number'];
echo"Name of student= $a->name</h2><br>";
echo"Roll number of student= $a->rno</h2>";
}
?>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<html>
<h2>T4Tutorials.com</h2>
<h3>Form program</h3>
<p>show output student name and roll number</p>
</html>
<html>
<body>
<form method="post">
<p>Enter Name</p>
<input type="text" name="name" />
<p>Enter Roll number</p>
<input type="text" name="number" />
<input type="submit" name="submit" />
</form>
<?php
class student
{
public $name= 'ali';
public $rno=77;
}
$a = new student();
if(isset($_POST['submit'])){
$a->name=$_POST['name'];
$a->rno=$_POST['number'];
echo"Name of student= $a->name</h2><br>";
echo"Roll number of student= $a->rno</h2>";
}
?>
</body>
</html>
PHP program to show the student information with a database
PHP
<html>
<head>
<style>
div {
align:center;
width:400px;
height:300px;
border: solid black;
background-color:orange;
padding: 20px;
}
</style>
</head>
<body>
<div>
<h1>Enter data for Student</h1>
<form method="post">
Name:<br />
<input type="text" name="name"/><br />
Roll number:<br />
<input type="text" name="rno"/>
<br><br>
<input type="submit" name="OK" />
</form>
<?php
$con=mysqli_connect("localhost","root","","student");
if(isset($_POST['OK'])){
$p =$_POST['name'];
$f =$_POST['rno'];
$sql=mysqli_query($con,"INSERT INTO students (name,rno) VALUES ('$p','$f')");
}
?>
</div>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<html>
<head>
<style>
div {
align:center;
width:400px;
height:300px;
border: solid black;
background-color:orange;
padding: 20px;
}
</style>
</head>
<body>
<div>
<h1>Enter data for Student</h1>
<form method="post">
Name:<br />
<input type="text" name="name"/><br />
Roll number:<br />
<input type="text" name="rno"/>
<br><br>
<input type="submit" name="OK" />
</form>
<?php
$con=mysqli_connect("localhost","root","","student");
if(isset($_POST['OK'])){
$p =$_POST['name'];
$f =$_POST['rno'];
$sql=mysqli_query($con,"INSERT INTO students (name,rno) VALUES ('$p','$f')");
}
?>
</div>
</body>
</html>
Answer:
Display my name in php:
php $name = $_POST[firstname]; $surname = $_POST[surname]; echo "Hello "; echo $name; echo " "; echo $surname; echo "<br />"; ?>
Explanation:
<!DOCTYPE html>
<html>
<body>
<h1>Students Detail</h1>
<form action="" method="post">
Enter roll no : <br>
<input type="text" name="r1"><br>
Enter your name : <br>
<input type="text" name="t1"><br>
<input type="submit" name="submit" value="submit">
</form>
<?php
$host_name="localhost";
$user_name="root";
$password="";
$connect = mysqli_connect($host_name,$user_name,$password);
if (isset($_POST['submit'])) {
$roll_no=$_POST['r1'];
$name=$_POST['t1'];
$sql = "insert into students_table values('".$roll_no."','".$name."')";
$result = mysqli_query($connect,$sql);
if ($result) {
echo "Data inserted";
}
else{
echo "Not inserted";
}
}?>
</body>
</html>