editing data, forms and default values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
compadre
Forum Newbie
Posts: 1
Joined: Sat Feb 15, 2003 10:34 am
Contact:

editing data, forms and default values

Post 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?
Last edited by compadre on Sun Feb 16, 2003 11:29 am, edited 1 time in total.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post 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.
}
?>
Post Reply