0

I have this code for listing mysql records and putting it into a table according to the address inputted. My problem is, how to do just the same but this time, making use of textboxes to project the contents of the record corresponding to the same data inputted. I'm just a beginner with no talent. Maybe you could give me some idea on how to do it.

       mysql_select_db("hospital", $con);

        $result = mysql_query("SELECT * FROM t2 WHERE ADDRESS='{$_POST["address"]}'");
         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>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['NURSE'] . "</td>";

  echo "</tr>";
     }
    echo "</table>";

 mysql_close($con);
   ?>
4
  • Could you clarify your question just a bit? You want the data retrieved from MySQL put into a text box? Commented Feb 7, 2010 at 8:40
  • So - you want to know how to use the <textarea> element? Or you want to know how to save a posted form (i.e., when the user changes and submits the record) into your database? Commented Feb 7, 2010 at 8:41
  • I don't know if was textarea or an input="text".., I just went ahead and assumed. Commented Feb 7, 2010 at 8:48
  • I like the way the question now has three separate answers for three separate interpretations. :-) Commented Feb 7, 2010 at 8:52

3 Answers 3

1

As a suggestion, I do not think displaying the values inside of a textbox is the best idea. With that being said, you achieve your results by performing the following

while($row = mysql_fetch_array($result)) {
 echo "<input type=\"text\" value='" . $row['HOSPNUM'] . "'><br />";
 echo "<input type=\"text\" value='" . $row['ROOMNUM'] . "'><br />";
 ....
}

You would need to escape the " inside of the text boxes by using PHP's escape special character \

Sign up to request clarification or add additional context in comments.

Comments

0

You need to search from your present tables and use AJAX to notify the user.

I would suggest you look into a framework in PHP which would help you a LOT since you are just starting your projects. List of frameworks can be found at http://www.phpframeworks.com/

Comments

0

As far as i could understand your question, you want to retrieve data from mysql based on the input of the text boxes. This is how you can go about it:

<form action="yourpage.php">
  <input type="text" name="text1">
  <input type="text" name="text2">
  <input type="text" name="text3">
</form>

Now you can retrieve data from mysql using where clause.

select * from table where text1 = 'text1' and  text2 = 'text2' and  text3 = 'text3'

Note: You need to change the names in form and query as per your requirement.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.