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

postgres=# CREATE DATABASE teacher;

ERROR: database "teacher" already exists


postgres=# CREATE DATABASE teacher1;
CREATE DATABASE
postgres=# \c teacher1;
You are now connected to database "teacher1" as user "postgres".
teacher1=# CREATE TABLE teacher(t_no int primary key, Name varchar(20), qualification
varchar(20), salary int);
CREATE TABLE
teacher1=# select * from teacher1;
ERROR: relation "teacher1" does not exist
LINE 1: select * from teacher1;
^
teacher1=# insert into teacher1 values(1, 'ram', 'bcs', 50000);
ERROR: relation "teacher1" does not exist
LINE 1: insert into teacher1 values(1, 'ram', 'bcs', 50000);
^
teacher1=# insert into teacher values(1, 'ram', 'bcs', 50000);
INSERT 0 1
teacher1=# insert into teacher values(2, 'ranjit', 'bcs', 30000);
INSERT 0 1
teacher1=# insert into teacher values(3, 'harsh', 'mcs', 60000);
INSERT 0 1
teacher1=# insert into teacher values(4, 'vikas', 'bca', 40000);
INSERT 0 1
teacher1=# select * from teacher1;
ERROR: relation "teacher1" does not exist
LINE 1: select * from teacher1;
^
teacher1=# select * from teacher;
t_no | name | qualification | salary
------+--------+---------------+--------
1 | ram | bcs | 50000
2 | ranjit | bcs | 30000
3 | harsh | mcs | 60000
4 | vikas | bca | 40000
(4 rows)

HTML :
<html>
<head>
<script type="text/javascript">
function displayTeacherInfo(){
var xmlHttp;
if(window.XMLHttpRequest)
xmlHttp = new XMLHttpRequest();
else
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
document.getElementById("myDiv").innerHTML = xmlHttp.responseText;
}
};
var tno = document.getElementById("tno").value;
xmlHttp.open("GET","tinfo.php?tno="+tno,true);
xmlHttp.send();
}
</script>
</head>
<body>
<h2>Please add Teacher Number in the textbox and press display button to get teacher
information</h2>
ENTER TEACHER NO<input type="text" name = "tno" id ="tno">
<input type="button" onclick="displayTeacherInfo()" value="print">
<div id="myDiv"></div>
</body>
</html>

PHP FILE DATABASE CONNECTION ASSINGMENT.4 SETB -1


<?php

$host = "localhost";
$user = "postgres";
$pass = "password";
$db = "teacher1";

$con = pg_connect("host=$host dbname=$db user=$user password=$pass");

<html>
<head>
<script type="text/javascript">
function displayTeacherInfo(){
var xmlHttp;
if(window.XMLHttpRequest)
xmlHttp = new XMLHttpRequest();
else
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
xmlHttp.onreadystatechange = function(){

if(xmlHttp.readyState == 4 && xmlHttp.status == 200)


{
document.getElementById("myDiv").innerHTML = xmlHttp.responseText;
}
};
var tno = document.getElementById("tno").value;
xmlHttp.open("GET","tinfo.php?tno="+tno,true);
xmlHttp.send();
}
</script>
</head>
<body>
<h2>Please add Teacher Number in the textbox and press display button to get teacher
information</h2>
ENTER TEACHER NO<input type="text" name = "tno" id ="tno">
<input type="button" onclick="displayTeacherInfo()" value="print">
<div id="myDiv"></div>
</body>
</html>if (!$con)
{
die ("could not connect to database server <br>");
}

else
{
echo "connection successful<br>";
}

$sql = "SELECT * FROM teacher";

$rs = pg_query($con,$sql) or die("unable to execute query:$sql".pg_last_error($con));

$rows=pg_num_rows($rs);
echo "There are currently $rs records in database.<br>";

if ($rows>0)
{
for ($i=0;$i<$rows;$i++)

{
$row=pg_fetch_row($rs,$i);
echo "<br>TEACHER NO:$row[0]<br> TEACHER NAME:$row[1]<br> QUALIFICATION:
$row[2]<br> SALARY:$row[3]";
}
}
else {
echo "No data is available";
}
pg_close($con)
?>

OUT PUT :

Please add Teacher Number in the textbox and press display


button to get teacher information
connection successful
There are currently Resource id #2 records in database.

TEACHER NO:1
TEACHER NAME:ram
QUALIFICATION:bcs
SALARY:50000
TEACHER NO:2
TEACHER NAME:ranjit
QUALIFICATION:bcs
SALARY:30000
TEACHER NO:3
TEACHER NAME:harsh
QUALIFICATION:mcs
SALARY:60000
TEACHER NO:4
TEACHER NAME:vikas
QUALIFICATION:bca
SALARY:40000

You might also like