Forum Moderators: coopster

Message Too Old, No Replies

Filling up text fields

         

ramoneguru

6:32 am on Apr 6, 2005 (gmt 0)

10+ Year Member



I have a record of a person (Name, Age, height, weight, Email) in a mysql database.

I would like to fill the results into a text box, then have the user update those boxes and resubmit it to the database. Then display the changes in the same boxes on the same page. Its not going too well on what I thought was a seemingly simple problem....

<?php
$address = someone@hotmail.com;

$result = mysql_query("SELECT ID, Name, Age, height, weight FROM Individual WHERE Email = '$address'") or die(mysql_error());

$row = mysql_fetch_array($result);

print "<form name=\"updatePro\" action=\"updateProfile.php\" method=\"post\")";

print "Name: ";
<input type=\"text\" name=\"name\" value=\"$row[Name]\" />

print "age: ";
<input type=\"text\" name=\"age\" value=\"$row[Age]\" />

print "height: ";
<input type=\"text\" name=\"height\" value=\"$row[height]\" />

print "weight: ";
<input type=\"text\" name=\"weight\" value=\"$row[weight]\" />

print "</form>\n";

$result = mysql_query("UPDATE Individual SET Name = '$fname', Age =? Where Email = '$address' ");
?>

Not sure if that is how its done...well, that last part sure is wrong since I couldn't get the update to work....Any ideas on how to do this?

--Nick

henry0

5:42 pm on Apr 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I read your form correctly you are
in and out of php
without "ending"!
<<<
print "Name: ";
<input type=\"text\" name=\"name\" value=\"$row[Name]\" />
>>>
After print (a php commend) you are ending the print
span by using ";
at this point you are still in PHP
but without exiting PHP you are using a mix of HTML and PHP
up to $row you are in HTML mode
but then in double jeopardy since you are commenting your HTML as in PHP
if you are not in PHP you should have something like
<input type="text" name="username" value="<? echo $username;?>">
if you are in full PHP
than you need to echo also from
<input etc... and enclose the line in between " "

HughMungus

6:20 pm on Apr 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have an off-topic suggestion for you: use echo instead of print.

print "<form name=\"updatePro\" action=\"updateProfile.php\" method=\"post\")";

becomes:

echo '<form name="updatePro" action="updateProfile.php" method="post")';

I switched after I got tired of commenting out quotation marks. Then, if you do want to include a PHP variable in what you're sending to the page, just do this:

'.$somevariable.'

For example:

$formname=updatePro;
echo '<form name="'.$formname.'" action="updateProfile.php" method="post")';

henry0

6:45 pm on Apr 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HughMungus
I often do the same but due to some old habits do also come back to the other way!

I know it should not
but I often think "does ir really matter?"
Henry

ramoneguru

7:44 pm on Apr 6, 2005 (gmt 0)

10+ Year Member



But how does the UPDATE work? I've changed the form to reflect your suggestions. I can fill the text fields w/ the data from the database, but I just can't UPDATE the database based on what the user inputs into those text boxes...how do I do that?
--Nick

henry0

8:23 pm on Apr 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nick
you might do a search on this board and look for update and insert

we do not see how looks: updateProfile.php

You are pointing to : updateProfile.php
So you need to feed updateProfile with your new data
print "<form name=\"updatePro\" action=\"updateProfile.php\" method=\"post\")";

the update file must contain the following to receive the values sent by the form

$username=$_POST['username'];
etc... one such per item....

then your DB section
$sql= "FROM Individual WHERE Email = '$address';
$sql = "update individual

and for example:

set username = '$username',
and the other var....
then
$result = mysql_query($sql, $conn);

if (!$result) {
print "There was a database error when executing <PRE>$sql</PRE>";
print mysql_error();
exit;