Re: Parsing Data, Table to Form

From: Paul Lynch <paul(dot)lynch(at)exemail(dot)com(dot)au>
To: Yasmine Kedoo <yazkedoo(at)hotmail(dot)com>, pgsql-php(at)postgresql(dot)org
Subject: Re: Parsing Data, Table to Form
Date: 2004-05-11 04:35:02
Message-ID: 40A057F6.4040503@exemail.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

Hi Yasmine,

Using your example as much as I can and assuming a single row is being
selected for updating. Your patid will be used in place of my
keyoftabledata (key of table data) variable.

In admininfo.php:
<?php
for ($rw = 0; $rw < $maxrows; $rw++)
{
for ($fld = 0; $fld < $maxfields ; $fld++)
{
echo pg_Result($result,$rw,$fld);
}
// I will assume that the key field is the first field in your
table result
pg_result($result,0,$patid); // add this line - you
could combine in one line
echo "<form method=post action=updaad.php>\n";
echo "<input type=\"hidden\" name=\"patid\"value=\"$patid\" >"
// add this line
echo "<input type=\"submit\" value=\"Update\" >"
// add this line as well
echo "</form>";
}
// this will give an update button for each row of data from your result
table
// I have left out the html table so as to simplify and avoid html
issues between tables and forms
// The only information being passed to updaat.php is the name patid
and its value
?>

So updaat.php will have the following:

<?php
$patid = $_POST["patid'];
// now use $patid to query the db for the row to update
$rowtoupdate = pg_exec($dbcon, "select patid, name, surname, phone, email
from your_table_name where patid=$patid"
); // patid is int ?
// where your_table_name is the name in postgresql
// and patid, name, surname, phone, email are the column names in the table
//
// add error checking etc here
// next lines assumes single row is available in $rowtoupdate
list($formatid,$formname,$formsurname,$formphone,$formemail) =
pg_fetch_row($rowtoupdate, 0 );
// need to start new form
echo "<form method=post action=writeat.php>\n"; // name the next
php program here
echo "Admin ID Number: <input type=text name=\"formadid\"
value=\"$formatid\"><br />\n";
echo "Name: <input type=text name=\"formname\" value=\"$formname\"><br
/>\n";
echo "Surname: <input type=text name=\"formsurname\"
value=\"$formsurname\"><br />\n";
echo "Phone: <input type=text name=\"formphone\"
value=\"$fornphone\"><br />\n";
echo "Email: <input type=text name=\"formemail\"
value=\"$formemail\"><br />\n";
// and so on for all your data
// need an update or accept button before writing back data changes
echo "<input type=\"submit\" value=\"Make Changes\" >"
echo "</form>";
?>

So finally we have the program that puts the data back to the database.
I have used writeat.php in this example, but use whatever name fits into
your naming convention.

The essence of writeat.php:
<?php
$patid = $_POST["formatid"];
$name = $_POST["formname"];
$surname = $_POST["formsurname"]
$phone = $_POST["formphone"];
$email = $+POST["formemail"];
$dbcon = pg_connect("dbname=your_db_name user=your_user");
pg_exec( $dbcon, "update your_table_name
set patid=$patid, // allowing the key to be
changed !!!!
name='$name',
surname='$surname',
phone='$phone',
email='$email'
where patid=$patid" );
?>

This is only one way of doing the required steps and it leaves all error
checking out .
One thing I don't like is allowing key fields to be changed so easily by
operator input, but you may have valid reasons for this. Generally I
hide the key fields from update screens unless required or useful to see.
My real programs have a lot of additional stuff but I will try and find
the simplest one to send to you off line.

Paul


Yasmine Kedoo wrote:

> Hi Paul.
>
> I think u do understand what i'm trying to do :-) , but i'm not too
> sure i understand what u've told me ;-)
>
> Do i need to repeat the following line for each bit of data in the table:
>
> echo "<input type=\"hidden\" name=\"patid\"value=\"$keyoftabledata\" >";
>
> where 'patid' is the ID field in the database. But I am unsure what to
> do with $keyoftabledata. What does this relate to?
>
> What does $keyforrow relate to here:
>
> $keyforrow = $_POST["yourkeyid"];
>
> Do i need to do this line a number of times for all data in the html
> table?
>
> If u dont mind, it would be nice if u could send me some sample
> programs relating to this topic.
>
> Thanx Again,
>
> Yasmine
>

Browse pgsql-php by date

  From Date Subject
Next Message Joe Nilson Zegarra Galvez 2004-05-12 13:49:50 about psql user
Previous Message Benjamin Schulz 2004-05-10 18:37:58 Re: field md5