Retrieve data from SQL table on a PostgreSQL server
Posted: Fri Nov 18, 2011 7:52 pm
Hi guys,
Basically, I have been given access to a database table called 'CSGames' which is in a database called 'teaching' on a PostgreSQL server. The table was created using the following SQL command:
I need to write some PHP and JavaScript with XHTML forms to start a session, and maintain it throughout, or until the user selects 'logout'. I then need to be able to query the data in the database table from the XHTML forms and display the results on a web page.
I have started writing the web pages, and have two so far: index.php and home.php
My index.php page looks like this:
My home.php page looks like this:
So, my problem is: I open up index.php in the browser- everything displays fine- great, no worries. I'm able to type my user name in the text box, and click 'submit'.
When I click submit, I'm taken to the home page, which is where I want to go, and my user name is displayed in a welcome message.
However, underneath the welcome message (where I'm trying to connect to the database), I get the error message "Fatal error: Call to undefined function pg_connect() in D:\filepath\home.php on line 11.
Could someone explain why I'm getting this error, and what I need to do to put it right, so that I'm able to establish a connection to the database, so that I can then go about retrieving data from it?
Thanks in advance!
Basically, I have been given access to a database table called 'CSGames' which is in a database called 'teaching' on a PostgreSQL server. The table was created using the following SQL command:
Code: Select all
CREATE TABLE CSGames
(
refnumber INT,
title VARCHAR (50),
platform VARCHAR (15),
description TEXT,
price DECIMAL (5, 2),
enteredby VARCHAR (20),
CONSTRAINT refnumber PRIMARY KEY (refnumber)
)I have started writing the web pages, and have two so far: index.php and home.php
My index.php page looks like this:
Code: Select all
<?
php session_start();
?>
<html>
<head><title>Log in</ title></ head>
<body><h1>Log in</ h1>
<form action="home.php" method="post">
Name: <input type="text" name="userName" />
<input type="Submit" />
</form>
</body>
</html>My home.php page looks like this:
Code: Select all
<html>
<head><title>Home</title></head>
<body>
<h1>Home</h1>
Welcome <?php echo $_POST["userName"]; ?>!
<?php
$dbconn = pg_connect("host=db.dcs.aber.ac.uk port=5432 dbname=******** user=******* password=*******");
// $conn = pg_connect("host=localhost port=5432 dbname=******** user=******* password=*******");
if(!$dbconn){
die('Could not connect: ' . pg_error());
}
?>
</body>
</html>When I click submit, I'm taken to the home page, which is where I want to go, and my user name is displayed in a welcome message.
However, underneath the welcome message (where I'm trying to connect to the database), I get the error message "Fatal error: Call to undefined function pg_connect() in D:\filepath\home.php on line 11.
Could someone explain why I'm getting this error, and what I need to do to put it right, so that I'm able to establish a connection to the database, so that I can then go about retrieving data from it?
Thanks in advance!