Tutorial :fill textbox with mysql data



Question:

How do I fill an inputbox with mysql data. So that I can update the database? I have this code that will show the table corresponding to the users request. But I don't know the syntax on how I can fill an inputbox with mysql data.

   $result = mysql_query("SELECT * FROM t2 WHERE STAT='{$_POST["stat1"]}'");          echo "<table border='1'>      <tr>   <th>HospNum</th>       <th>RoomNum</th>   <th>LastName</th>     <th>FirstName</th>     <th>MidName</th>      <th>Address</th>     <th>TelNum</th>     <th>Status</th>     <th>Nurse</th>     </tr>";       while($row = mysql_fetch_array($result))    {     echo "<tr>";    echo "<td>" . $row['HOSPNUM'] . "</td>";     echo "<td>" . $row['ROOMNUM'] . "</td>";       echo "<td>" . $row['LASTNAME'] . "</td>";     echo "<td>" . $row['FIRSTNAME'] . "</td>";      echo "<td>" . $row['MIDNAME'] . "</td>";        echo "<td>" . $row['ADDRESS'] . "</td>";         echo "<td>" . $row['TELNUM'] . "</td>";          echo "<td>" . $row['STAT'] . "</td>";          echo "<td>" . $row['NURSE'] . "</td>";  

echo ""; } echo "";

And I want to display the corresponding records with this html form, by inputting a primary key. And clicking the search button, the record will appear on each box. Just like when you update mysql database through phpmyadmin. But this time using a custom html form.

<td width="168"><input name="hnum" type="text" id="hospnum"></td>  <td width="41"><font size="3">Room #</td>  <td width="3">:</td>   <td width="168"><input name="rnum" type="text" id="rnum"></td>  

how can I do that?


Solution:1

<input name="hnum" type="text" id="hospnum" value="<?php echo $row['ROOMNUM']; ?>" />  


Solution:2

In text field you have fill the value attribute with php fetched attribute value

echo "<input name='rnum' type='text' id='rnum' value =".$row['ROOMNUM'].">";  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »