By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,743 Members | 1,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,743 IT Pros & Developers. It's quick & easy.

how to update a table in a database by a html form

P: 32
I had made a persons profile in a html page and stored the data in a postgre database. Now I want that, when the person visit his profile page only that person should be able to update the profile and data should be update in the database. And when he go to the editable mode data should be fetched from database and when he update the profile database should also be updated.
Jan 8 '07 #1
Share this Question
Share on Google+
4 Replies


ronverdonk
Expert 2.5K+
P: 4,258
First you must have established some level of authority in your db. Meaning that, after a user has logged in and been succesfully verified, you can tie that (unique) login userdata to only one unique profile (set of) record(s) only. Such as [php]SELECT * from profile_table WHERE userid='$login_data' .... ;[/php]
The same applies to all operations on that data, like INSERT and UPDATE. Always verify that such an operation on that particular data can only be performed by the verified user.

Ronald :cool:
Jan 8 '07 #2

P: 32
First you must have established some level of authority in your db. Meaning that, after a user has logged in and been succesfully verified, you can tie that (unique) login userdata to only one unique profile (set of) record(s) only. Such as [php]SELECT * from profile_table WHERE userid='$login_data' .... ;[/php]
The same applies to all operations on that data, like INSERT and UPDATE. Always verify that such an operation on that particular data can only be performed by the verified user.

Ronald :cool:
how to give login and password to a table in pgsql database? and after that how can I fetch the data from that table and display it in a html form so that the client can edit it and the edited information is update in the database.
Jan 10 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
Show us what code you have developed until now and we will see how we can help you out. (don't forget to enclose that code within the appropriate code, html or php tags!! See the Posting Guidelines).

Ronald :cool:
Jan 10 '07 #4

P: 32
Show us what code you have developed until now and we will see how we can help you out. (don't forget to enclose that code within the appropriate code, html or php tags!! See the Posting Guidelines).

Ronald :cool:
I had made a html file that is:
[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<html>
<body>
<form action="add.php" method="post">
First Name : <input type="text" name="firstname" size="40" length="40" value="First Name"><BR>
Surname : <input type="text" name="surname" size="40" length="40" value="Surname"><BR>
Email Address : <input type="text" name="emailaddress" size="40" length="40" value="Email Address"><BR>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Clear It">
</form>
</body>
</html> [/HTML]

and my add.php goes like this:
[PHP]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
$db = pg_connect('host=172.28.44.75 dbname=personal user=postgres password=');

$firstname = pg_escape_string($_POST['firstname']);
$surname = pg_escape_string($_POST['surname']);
$emailaddress = pg_escape_string($_POST['emailaddress']);

$query = "INSERT INTO friends(firstname,surname,emailaddress) VALUES('" . $firstname . "', '" . $surname . "', '" . $emailaddress . "')";
$result = pg_query($query);
if (!$result) {
$errormessage=pg_last_error();
echo "Error with query: " . $errormessage;
exit();
}
printf ("These values were inserted into the database - %s %s %s", $firstname, $surname, $emailaddress);
pg_close();
?>
</body>
</html>[/PHP]

but after running this program I got an error that is:

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Warning: Unable to connect to PostgreSQL server: No pg_hba.conf entry for host 172.28.44.75, user postgres, database personal in /web/train06/myphp/add.php on line 11

Fatal error: Call to undefined function: pg_escape_string() in /web/train06/myphp/add.php on line 13

can u tell me that where i am going wrong.
Jan 11 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.