Page 1 of 1

[php] fill form fields with data from database

Posted: Mon Jun 09, 2008 7:50 am
by natomiast
Hello!
Is that is possible to fill form fields with data from database without using JS or Ajax (or both)?
I have somthing like this but it doesn't work :(

Code: Select all

 
                                $result = mysql_query("SELECT imie FROM nauczyciel ORDER BY nazwisko");
                                $result= mysql_query($result);
                                          while ($field= mysql_fetch_object($result))
                                          {
                                          $field1 = $field->imie;
                                          }
                                           echo mysql_error() ;
                                    <form method="POST">
                                    <input type="text" name="fimie<?php $field1  ?>"> <br><br>
                                    <input type="text" name="imie_nauczyciela" value="'.$imie.'"/>
                                    </form>
 
I have some msql error :"Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:\Program Files\WebServ\my_www\admin\modyfikacja_nauczyciela.php on line 43"
Thnx for help :)

Re: [php] fill form fields with data from database

Posted: Mon Jun 09, 2008 8:07 am
by madan koshti
Hi,

Try this,Hope it will work!

<form method="POST">
<?php
mysql_connect("hostname", "user", "password");
mysql_select_db("mydb");
$result = mysql_query("SELECT imie FROM nauczyciel ORDER BY nazwisko");
while ($field= mysql_fetch_object($result)) {
$field1 = $field->imie;
echo "<input type=text name=fimie$field1><br><br>
<input type=text name=imie_nauczyciela value=$imie/>";
}

mysql_free_result($result);
?>
</form>