display edited field in table
| From: | Lightfirst | Date: | Thu, 19 Dec 2002 09:44:52 +0000 |
| Subject: | display edited field in table | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-128821@lists.php.net to get a copy of this message | ||
I am using Php/MySql and I am trying to display a table and have one of the
fields (answer) editable. What I would like is to have the user edit the
field and then click update. The result- display the table along with the
updated field. What am I doing wrong? He is my code:
<?php
include "./common_db.inc"; file://sets up databse stuff
db_connect("test");
GLOBAL $PHP_SELF;
?>
<html>
<?php
if ($id){
$query = "UPDATE questions SET answer = '$a' Where q_id = '$id'";
$result = mysql_query($query);
if (!$result) error_message(sql_error());
}
$query = "SELECT * FROM questions";
$result = mysql_query($query);
if (!result) error_message (sql_error());
?>
<table width=75% border=1>
<?php while($query_data = mysql_fetch_array($result)) { ?>
<form name="update" method="post" action="<?php echo
$PHP_SELF?>">
<TR>
<? $id = $query_data ["q_id"];
$q = $query_data ["question"];
$a = $query_data ["answer"]; ?>
<TD WIDTH=5% ALIGN=CENTER> <?php echo"$id"; ?> </TD>
<TD WIDTH=70% ALIGN=CENTER> <?php echo"$q"; ?> </TD>
<TD WIDTH=15% ALIGN=CENTER> <input type="text" name="textfield"
value="<?php
echo"$a"; ?>"> </TD>
<TD WIDTH=10% ALIGN=CENTER> <input type="submit" name="input"
value="Update">
</form>
</TD>
</TR>
<?php }?>
</table>
</html>
-Thanks.