From: David Mehler on
Hello,
Not sure if this went out, apologies if this is a double post.
I'm having difficulty tying something together. I'm wanting to display
a record from a database in a form, information from the various
fields in the database goes in to their coresponding fields in the
form, for example address field of the database goes in to the address
field of the form etc. If I then edit and resubmit that same form the
field or fields edited and only them will be updated. I'd like this to
be all in one file.
This tells me I need three queries, one a method to display records
for selection and editing which I have, the second to select the
specific record based on the ID in this case and to put that in the
form which isn't working the form display part, and the third to
update any altered fields which I don't have.
If anyone has code like this i'd appreciate it.
Thanks.
Dave.
From: Sky Gunning on
Hello

I think your code would be very nice to be able to hep you out or correct
your methods.

On Tue, Aug 3, 2010 at 1:33 AM, David Mehler <dave.mehler(a)gmail.com> wrote:

> Hello,
> Not sure if this went out, apologies if this is a double post.
> I'm having difficulty tying something together. I'm wanting to display
> a record from a database in a form, information from the various
> fields in the database goes in to their coresponding fields in the
> form, for example address field of the database goes in to the address
> field of the form etc. If I then edit and resubmit that same form the
> field or fields edited and only them will be updated. I'd like this to
> be all in one file.
>

You mean all you php + html code in the same file ?


> This tells me I need three queries, one a method to display records
> for selection and editing which I have, the second to select the
> specific record based on the ID in this case and to put that in the
> form which isn't working the form display part, and the third to
> update any altered fields which I don't have.
>

From what i gather, you will need 2 query's : 1 select and 1 update.
Dont understand what that third one does.

If anyone has code like this i'd appreciate it.
> Thanks.
> Dave. <http://www.php.net/unsub.php>
>
>
here is a quick and dirty example :

<?php
$id = (int)$_GET['id'];

$requete = "SELECT * FROM Users WHERE id='$id'";
$sql = mysql_query($requete);
$user = mysql_fetch_assoc($sql);


if(!$_POST)
{
echo '
<form action="" method="post">

<h3>Email</h3>
<p><input type="text" name="email"
value="'.htmlentities($user['email']).'" /></p>

<h3>Login</h3>
<p><input type="text" name="login"
value="'.htmlentities($user['login']).'" /></p>

<h3>Mot de passe</h3>
<p><input type="text" name="password"
value="'.htmlentities($user['password']).'" /></p>

</form>';
}
else
{

$login = mysql_real_escape_string($_POST['login']);
$email = mysql_real_escape_string($_POST['email']);
$password = mysql_real_escape_string($_POST['password']);

$requete = "UPDATE Users SET login='$login', email='$email',
password='$password'";
mysql_query($requete);

}
?>


You can make this much better by getting the fields list from the database
before displaying the form, then display the form according to fields
informations.
The update can also be much better like building the update query according
to the POST array and confirming the each key with the table fields.


Sry if i did not understand you right.


Sky_G