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?
editing data, forms and default values
Moderator: General Moderators
editing data, forms and default values
Last edited by compadre on Sun Feb 16, 2003 11:29 am, edited 1 time in total.
To set a default value for forms, you should use 'value' attribute as follows:-
If the form you're dealing with is TEXTAREA just put the default value between the tag as follows:-
To read the data from the database you can use code something like this:-
Code: Select all
<input type="text" name="1" value="hello">Code: Select all
<textarea>
Hello
</textarea>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.
}
?>