Steps to run database project using Postgres and PHP
1)create connection.php file like
$con_string="host=localhost dbname=yourdatabasename user=postgres password=abc";
if($con=pg_connect($con_string))
{
echo "Connected to Database";
echo $con;
}
?>
run this file in the browser and check is it working or not.
2)If there are authentication issues for postgres then try to alter password
command:
postgres@host$ psql "alter user postgres with password 'abc'"
3) Insert in database
include connection.php file created in step1
a) fetch data values from html file you have created.
$roll=$_POST['rl'];
$name=$_POST['nm'];
b) first check by displaying those with echo statements in php
echo $roll;
echo $name;
c) if step b is done then comment all the line used in it.
/*echo $roll;
echo $name;*/
d) check for empty values and fire insert query
if($roll!="" && $name!="")
{
$q="insert into student values('$roll','$name')";
$chk=pg_query($con,$q);
if($chk)
echo "Data inserted";
else
echo "Data not inserted";
}
else
echo "Data not inserted";
1)create connection.php file like
$con_string="host=localhost dbname=yourdatabasename user=postgres password=abc";
if($con=pg_connect($con_string))
{
echo "Connected to Database";
echo $con;
}
?>
run this file in the browser and check is it working or not.
2)If there are authentication issues for postgres then try to alter password
command:
postgres@host$ psql "alter user postgres with password 'abc'"
3) Insert in database
include connection.php file created in step1
a) fetch data values from html file you have created.
$roll=$_POST['rl'];
$name=$_POST['nm'];
b) first check by displaying those with echo statements in php
echo $roll;
echo $name;
c) if step b is done then comment all the line used in it.
/*echo $roll;
echo $name;*/
d) check for empty values and fire insert query
if($roll!="" && $name!="")
{
$q="insert into student values('$roll','$name')";
$chk=pg_query($con,$q);
if($chk)
echo "Data inserted";
else
echo "Data not inserted";
}
else
echo "Data not inserted";