473,748 Members | 6,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTML forms and Postgres

I am new to PHP but not so new to Postgres. If someone can either
direct me to some howto or even provide me with an example, I would be
grateful.

I would like to know if it is possible to create an HTML form text box
that can draw information out of the database and display it in the
HTML form text box. I have purchased a few books on the integration of
Postgres and PHP but can find no such example. Maybe there is a better
way of doing this?

My theory is that if I can draw this information from the database and
have it displayed in the HTML form text box, this same information can
be UPDATED if need be from the same page. Any information or a point in
the right direction, again would be appriciated.

Frank

Jul 15 '06 #1
3 4498
I have purchased 6 books. 3 being from ora.com and still nothing on
textboxes and database. Can anyone else help?
Michael Vilain wrote:
In article <11************ **********@75g2 000cwc.googlegr oups.com>,
"fjm67" <fj*********@ya hoo.comwrote:
I am new to PHP but not so new to Postgres. If someone can either
direct me to some howto or even provide me with an example, I would be
grateful.

I would like to know if it is possible to create an HTML form text box
that can draw information out of the database and display it in the
HTML form text box. I have purchased a few books on the integration of
Postgres and PHP but can find no such example. Maybe there is a better
way of doing this?

My theory is that if I can draw this information from the database and
have it displayed in the HTML form text box, this same information can
be UPDATED if need be from the same page. Any information or a point in
the right direction, again would be appriciated.

Frank

Most of the books I've seen on PHP and databases use the MySQL database
rather than Postgres. But, the approach is the same, especially if you
use a database abastraction layer like the PEAR DB class. I chose to
use a MySQL layer from a php library site. I'm really surprised that
the book you have doesn't supply examples. I'd return it to where you
bought it and complain to the seller that it's useless. If you paid
with a credit card, contest the charge.

If you go to the O'Reilly site (http://www.ora.com), there are _lots_ of
books on php. Or find a local technical book store and browse on your
own to find what suits your needs.

And to clarify your assumption about PHP and databases: you extract the
information from the database with a SQL statement, then write the
information out in properly formatted HTML. This requires you to
understand how your database works, how to construct a HTML page, and
how to program in PHP. Lots of books to buy...

--
DeeDee, don't press that button! DeeDee! NO! Dee...
Jul 16 '06 #2

fjm67 wrote:
I have purchased 6 books. 3 being from ora.com and still nothing on
textboxes and database. Can anyone else help?
Look for these functions on php.net for information:

pg_pconnect()
pg_query()
pg_fetch_assoc( )
pg_escape_strin g()
htmlspecialchar s()
urlencode()

pg_pconnect will connect to the database. Unlike MySQL, PostgreSQL
requires a seperate connection for each database even on the same
server so if you will be using multiple databases you will need
multiple pg_pconnect calls. If pg_pconnect returns false it failed.
Otherwise it will give you the connection object that you need to pass
to the rest of the functions to interact with the database you
connected to.

$dcn = pg_pconnect('ho st=localhost port=5432 dbname=mydb user=foo
password=bar');
if ($dcn === false) die('connection error');

Next, make sure after you do pg_query you make a check for errors.
pg_query returns false when it fails, otherwise it returns a result
resource. I recommend always specifying the schema name for each table
and putting double-quotes around schema, table and column names. The
SQL for pg_query is going to be something like:

$sql = 'SELECT "MyTextFiel d" FROM "MySchema"."MyT able";';
$res = pg_query($dcn, $sql);
if ($res === false) die('query error');
htmlspecialchar s was used to ensure that any quotes in the string
returned from the database don't cause problems with our HTML output.
If you inject database data into a href attribute of an a tag (or into
any other url) you should use urlencode instead. Use pg_fetch_assoc
together with a while loop:

while ($row = pg_fetch_assoc( $res)) {
echo '<input type="text"
value="'.htmlsp ecialchars($row['MyTextField']).'" />';
}

I usually process form data in the same file that generates the form
itself. I use a submit button with the name "Action" to handle
different commands. Processing form data works like this:

if (isset($_POST['action'])) {
// if action has been received we are receiving a submission
switch ($action) {
case 'Update':
$sql = 'UPDATE "MySchema"."MyT able" SET "MyTextFiel d" =
\''.pg_escape_s tring($_POST['MyTextField']).'\' WHERE
id='.intval($_P OST['id']).';';
$res = pg_query($dcn, $sql);
if ($res === false) die('update error');
break;
}
}

None of the above has been tested and is from memory. But hopefully
that's enough to get you started.

-Robert
Michael Vilain wrote:
In article <11************ **********@75g2 000cwc.googlegr oups.com>,
"fjm67" <fj*********@ya hoo.comwrote:
I am new to PHP but not so new to Postgres. If someone can either
direct me to some howto or even provide me with an example, I would be
grateful.
>
I would like to know if it is possible to create an HTML form text box
that can draw information out of the database and display it in the
HTML form text box. I have purchased a few books on the integration of
Postgres and PHP but can find no such example. Maybe there is a better
way of doing this?
>
My theory is that if I can draw this information from the database and
have it displayed in the HTML form text box, this same information can
be UPDATED if need be from the same page. Any information or a point in
the right direction, again would be appriciated.
>
Frank
Most of the books I've seen on PHP and databases use the MySQL database
rather than Postgres. But, the approach is the same, especially if you
use a database abastraction layer like the PEAR DB class. I chose to
use a MySQL layer from a php library site. I'm really surprised that
the book you have doesn't supply examples. I'd return it to where you
bought it and complain to the seller that it's useless. If you paid
with a credit card, contest the charge.

If you go to the O'Reilly site (http://www.ora.com), there are _lots_ of
books on php. Or find a local technical book store and browse on your
own to find what suits your needs.

And to clarify your assumption about PHP and databases: you extract the
information from the database with a SQL statement, then write the
information out in properly formatted HTML. This requires you to
understand how your database works, how to construct a HTML page, and
how to program in PHP. Lots of books to buy...

--
DeeDee, don't press that button! DeeDee! NO! Dee...
Jul 16 '06 #3

"rlee0001" <ro*********@ho tmail.comwrote in message
news:11******** **************@ 35g2000cwc.goog legroups.com...
>
fjm67 wrote:
>I have purchased 6 books. 3 being from ora.com and still nothing on
textboxes and database. Can anyone else help?

Look for these functions on php.net for information:

pg_pconnect()
pg_query()
pg_fetch_assoc( )
pg_escape_strin g()
htmlspecialchar s()
urlencode()

pg_pconnect will connect to the database. Unlike MySQL, PostgreSQL
requires a seperate connection for each database even on the same
server so if you will be using multiple databases you will need
multiple pg_pconnect calls.
This is slightly misleading. With PostgreSQL you connect to a "database",
but within each "database" there can be multiple "schemas". With MySQL you
connect to "server", and with each server you can have multiple "databases" .
What is called a "schema" in PostgrSQL is called a "database" in MySQL. This
is a typical case of different organisations using the same word to mean
different things, thus causing confusion. I believe in the SQL standard that
"database" and "schema" mean the same thing, while a collection of "database
schemas" is known as a "catalog".

--
Tony Marston

http://www.tonymarston.net
http://www.radicore.org
If pg_pconnect returns false it failed.
Otherwise it will give you the connection object that you need to pass
to the rest of the functions to interact with the database you
connected to.

$dcn = pg_pconnect('ho st=localhost port=5432 dbname=mydb user=foo
password=bar');
if ($dcn === false) die('connection error');

Next, make sure after you do pg_query you make a check for errors.
pg_query returns false when it fails, otherwise it returns a result
resource. I recommend always specifying the schema name for each table
and putting double-quotes around schema, table and column names. The
SQL for pg_query is going to be something like:

$sql = 'SELECT "MyTextFiel d" FROM "MySchema"."MyT able";';
$res = pg_query($dcn, $sql);
if ($res === false) die('query error');
htmlspecialchar s was used to ensure that any quotes in the string
returned from the database don't cause problems with our HTML output.
If you inject database data into a href attribute of an a tag (or into
any other url) you should use urlencode instead. Use pg_fetch_assoc
together with a while loop:

while ($row = pg_fetch_assoc( $res)) {
echo '<input type="text"
value="'.htmlsp ecialchars($row['MyTextField']).'" />';
}

I usually process form data in the same file that generates the form
itself. I use a submit button with the name "Action" to handle
different commands. Processing form data works like this:

if (isset($_POST['action'])) {
// if action has been received we are receiving a submission
switch ($action) {
case 'Update':
$sql = 'UPDATE "MySchema"."MyT able" SET "MyTextFiel d" =
\''.pg_escape_s tring($_POST['MyTextField']).'\' WHERE
id='.intval($_P OST['id']).';';
$res = pg_query($dcn, $sql);
if ($res === false) die('update error');
break;
}
}

None of the above has been tested and is from memory. But hopefully
that's enough to get you started.

-Robert
>Michael Vilain wrote:
In article <11************ **********@75g2 000cwc.googlegr oups.com>,
"fjm67" <fj*********@ya hoo.comwrote:

I am new to PHP but not so new to Postgres. If someone can either
direct me to some howto or even provide me with an example, I would
be
grateful.

I would like to know if it is possible to create an HTML form text
box
that can draw information out of the database and display it in the
HTML form text box. I have purchased a few books on the integration
of
Postgres and PHP but can find no such example. Maybe there is a
better
way of doing this?

My theory is that if I can draw this information from the database
and
have it displayed in the HTML form text box, this same information
can
be UPDATED if need be from the same page. Any information or a point
in
the right direction, again would be appriciated.

Frank

Most of the books I've seen on PHP and databases use the MySQL database
rather than Postgres. But, the approach is the same, especially if you
use a database abastraction layer like the PEAR DB class. I chose to
use a MySQL layer from a php library site. I'm really surprised that
the book you have doesn't supply examples. I'd return it to where you
bought it and complain to the seller that it's useless. If you paid
with a credit card, contest the charge.

If you go to the O'Reilly site (http://www.ora.com), there are _lots_
of
books on php. Or find a local technical book store and browse on your
own to find what suits your needs.

And to clarify your assumption about PHP and databases: you extract the
information from the database with a SQL statement, then write the
information out in properly formatted HTML. This requires you to
understand how your database works, how to construct a HTML page, and
how to program in PHP. Lots of books to buy...

--
DeeDee, don't press that button! DeeDee! NO! Dee...

Jul 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4205
by: N.K. | last post by:
Hi, I've just installed postgres on the Linux server. It is supposed to start automatically which I think it does since I can run an sql stmt right away. When I'm trying to connect from a remote machine I get a message that the remote machine IP address is not specified in pg_hba.conf, that there is no record of that machine there. ph_hba.conf is set up correctly, because when I run the following: postmaster -i -D /var/lib/pgsql/data...
7
6664
by: Abdul-Wahid Paterson | last post by:
Hi, I have had a site working for the last 2 years and have had no problems until at the weekend I replace my database server with a newer one. The database migration went like a dream and I had the whole db changed over in 1 hour. Since the upgrade I have been getting the following error message sporadically.
15
4300
by: Birahim FALL | last post by:
Hi, I'm very fresh to PostgreSQL, coming from Oracle. I want to developp web applications based on apache and postgresql. Is there an equivalent of OWA server (Oracle Web Application server) for postgresql. Shortly, OWA provides an apache module and a set of stored procedures/functions that generate html pages. A simple example could be the following procedure :
18
2024
by: Chris Travers | last post by:
Hi all; I have been looking into how to ensure that synchronous replication, etc. could best be implimented. To date, I see only two options: incorporate the replication code into the database backend or have a separate "proxy" which handles the replication. The main problem with incorporating the system into the backend process is that it limits the development to the 10-month timeframe between releases. The main advantage is that...
3
8703
by: warwick.poole | last post by:
I am interested in finding out about Enterprise scale Postgres installations and clustering, especially on Linux. Essentially I would like to know the possibility that Postgres can store the database data in a central location (ex: on a SAN fiber array) and have a cluster of machines sharing processor/RAM/IO bandwidth to do the application processing. Or perhaps there is another solution similar to what www.emicnetworks.com have...
6
2954
by: Prabu Subroto | last post by:
Dear my friends... Usually I use MySQL. Now I have to migrate my database from MySQL to Postgres. I have created a database successfully with "creatdb" and a user account successfully. But I can not access the postgres with pgaccess.
18
5152
by: Joe Lester | last post by:
This thread was renamed. It used to be: "shared_buffers Question". The old thread kind of died out. I'm hoping to get some more direction by rephrasing the problem, along with some extra observations I've recently made. The core of the problem is that Postgres is filling up my hard drive with swap files at the rate of around 3 to 7 GB per week (that's Gigabytes not Megabytes) . At this rate it takes roughly two months to fill up my 40...
1
3866
by: Jack Orenstein | last post by:
I'm trying to configure PHP 5.2.0 with support for Postgres 8.1.3. Postgres was installed with FC5 without source. PHP's configure needs source. When I run configure: configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path I tried downloading Postgres source and modifying PHPs configure to point to it, and that worked. But then compilation failed, e.g.
0
2705
by: NM | last post by:
Hello, I've got a problem inserting binary objects into the postgres database. I have binary objects (e.g. images or smth else) of any size which I want to insert into the database. Funny is it works for files larger than 8000 Bytes. If a file is less than 1000 Bytes I get the following message: Error message: --invalid input syntax for type oid: "\074\077......";
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.