Page 1 of 1

editing data, forms and default values

Posted: Sat Feb 15, 2003 10:34 am
by compadre
I have a problem updating data in a MySQL database using HTML forms and PHP scripts:

I need to modify data from one database register and I want to do this in this way:

1.- One PHP script read data from a MySQL database and store it in some variables (no problema with this)
2.- A HTML form must include these values as default values, in order to let me modify as necessary (I don't know how to mek this)
3.- Another PHP script validates the form and update database (no problem)

How can I do this?

Posted: Sat Feb 15, 2003 11:21 am
by Takuma
To set a default value for forms, you should use 'value' attribute as follows:-

Code: Select all

<input type="text" name="1" value="hello">
If the form you're dealing with is TEXTAREA just put the default value between the tag as follows:-

Code: Select all

<textarea>
Hello
</textarea>
To read the data from the database you can use code something like this:-

Code: Select all

<?php
mysql_connect("","","");
mysql_select_db("");

//Reads all the data in the table 'register'
$sql = "SELECT * FROM registers";
//Alternatively you can select which columns to read as follows
//$sql = "SELECT col1, col2 FROM registers";
//For more information read the MySQL manual

//Execute the query and put the result in $result
$result = mysql_query($sql);
while($row = $data = mysql_fetch_array($result)) {
  echo $row1['col1'];
  //etc.
}
?>