|
Posted by Rik on 07/16/06 12:14
fjm67 wrote:
> If someone can either direct me to some howto or even provide me with
> an example, I would be grateful.
>
> I would like to know if it is possible to create an HTML form text box
> that can draw information out of the database and display it in the
> HTML form text box. I have purchased a few books on the integration of
> databases and PHP but can find no such example. Maybe there is a
> better
>
> way of doing this?
>
> My theory is that if I can draw this information from the database and
> have it displayed in the HTML form text box, this same information can
> be UPDATED if need be from the same page. Any information or a point
> in
- Assuming a table tbl_name, with fields id & text
- Displaying and updating all records at once
- Simpified code, without error checking and hence a major security risk:
<form action="<?php echo $_SERVER['PHP_SELF']; ?> method="post">
<?php
$con = mysql_connect('host', 'user', 'pass');
mysql_select_db('db',$con);
if(isset($_POST['submit'])){
foreach($_POST['text'] as $id => $text){
mysql_query("UPDATE tbl_name SET `text` = '{$text}' WHERE `id` =
$id");
}
}
$result=mysql_query("SELECT id,text FROM tbl_name");
while($row = mysql_fetch_array($result)){
echo '<textarea
name="text['.$row['id'].']">'.$row['text'].'</textarea>';
}
?>
<input type="submit" name="submit" value="change" />
</form>
If you have purchased some books I assums they will tell you what to do
about safety...
Grtz,
--
Rik Wasmus
[Back to original message]
|