Retrieving data from database and displaying in textbox/text area

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikas1111
    New Member
    • Feb 2008
    • 122

    Retrieving data from database and displaying in textbox/text area

    Hi All


    Can anyone give me an idea to solve the problem.. My Problem is ,, I want to Retrieving data from database and displaying in textbox... If anybody have link of some good tutorial on this pls let me know..Or if anybody can explain I would be very thankful...
  • coolsti
    Contributor
    • Mar 2008
    • 310

    #2
    You are asking a very general basic question, and I believe this forum tries to help with more specific problems. But to get you started, let us assume you wish to use PHP on the server side to interact with your database and then produce HTML output to send to the user's browser. And the database values are to be shown in the forms in the page that the HTML produces in the user's browser.

    So you need to know how to invoke a PHP script on the server, how to get the PHP script to connect to your database, how to do a "select" query to get the data you want out of the database table or tables, how to then put those values into PHP variables which then can be outputted in the HTML that will produce the page. So you also need to know how to produce the HTML with the forms that you want, and how to place the PHP variables that came from the database into the forms in the proper place rather than just "hard coding" static variables there.

    Just take the above one at a time and look at some documentations for PHP, SQL, HTML, etc.

    Comment

    • vikas1111
      New Member
      • Feb 2008
      • 122

      #3
      Thanks coolsti

      How to place the PHP variables that come from the database into the forms in the proper place .i.e. in txt box or txt area...


      I just want to know obout the above line....Other things i know..

      Comment

      • rpnew
        New Member
        • Aug 2007
        • 189

        #4
        Originally posted by vikas1111
        Hi All


        Can anyone give me an idea to solve the problem.. My Problem is ,, I want to Retrieving data from database and displaying in textbox... If anybody have link of some good tutorial on this pls let me know..Or if anybody can explain I would be very thankful...
        Hi,
        I've seen your last post regarding inserting data problem so i guess you know how to use PHP to get data.. and put it them into variable. So you can simple do the following to display it in the text box...
        1.
        [PHP]
        <?php
        //your php code for fetching data and geting them into variable
        ?>

        <input type="text" name="xyz" value=<?php echo $val; ?> >
        [/PHP]
        or
        2.
        [PHP]
        <?php
        //your php code for fetching data and geting them into variable

        echo "<input type=\"text\" name=\"xyz\" value='$val'>";
        [/PHP]

        You can use either of the way... just be careful with escaping " in second example..

        This is not related to your problem exactly but you may find this
        thread useful for comparision for above two ways

        Comment

        • vikas1111
          New Member
          • Feb 2008
          • 122

          #5
          Originally posted by rpnew
          Hi,
          I've seen your last post regarding inserting data problem so i guess you know how to use PHP to get data.. and put it them into variable. So you can simple do the following to display it in the text box...
          1.
          [PHP]
          <?php
          //your php code for fetching data and geting them into variable
          ?>

          <input type="text" name="xyz" value=<?php echo $val; ?> >
          [/PHP]
          or
          2.
          [PHP]
          <?php
          //your php code for fetching data and geting them into variable

          echo "<input type=\"text\" name=\"xyz\" value='$val'>";
          [/PHP]

          You can use either of the way... just be careful with escaping " in second example..

          This is not related to your problem exactly but you may find this
          thread useful for comparision for above two ways

          Thanks

          I am trying tp do in this way but its not working..


          [PHP]
          while($row = mysql_fetch_arr ay($result))
          {
          echo "<input type="text" name="txtname" value='$row['id']'>";
          }
          [/PHP]


          Connection and mysql syntax are correct..Only problem in displaying in textbox..

          I am getting proper output to the bellow code...
          [PHP]

          while($row = mysql_fetch_arr ay($result))
          {
          echo "<td>" . $row['id'] . "</td>";
          }

          [/PHP]

          Comment

          • rpnew
            New Member
            • Aug 2007
            • 189

            #6
            Originally posted by vikas1111
            Thanks

            I am trying tp do in this way but its not working..


            [PHP]
            while($row = mysql_fetch_arr ay($result))
            {
            echo "<input type="text" name="txtname" value='$row['id']'>";
            }
            [/PHP]


            Connection and mysql syntax are correct..Only problem in displaying in textbox..

            I am getting proper output to the bellow code...
            [PHP]

            while($row = mysql_fetch_arr ay($result))
            {
            echo "<td>" . $row['id'] . "</td>";
            }

            [/PHP]
            First tell me what are you geting as output...

            second thing i guess you need to escape your ' into your example like this... try this..
            [PHP]
            echo "<input type="text" name="txtname" value='$row[\'id\']'>";

            [/PHP]

            Regards,
            RP

            Comment

            • vikas1111
              New Member
              • Feb 2008
              • 122

              #7
              I have created a table in mysql database to insert some records say students or employee records.. Now what i have to do is i have to display all the records in admin view page..( which i have done).. There is an option provided for editing the records beside every record.. So when the admin clicks on the edit button another form should open which will contain information of the user in the text box so that he can just edit and save the changes back into the databse..

              This is a part of what i have coded..

              [PHP]
              include("connec tion.php");
              $result = mysql_query("SE LECT * FROM usttable");
              while($row = mysql_fetch_arr ay($result))
              {
              echo "<input type="text" name="txtname" value='$row[\'id\']'>";
              }

              [/PHP]

              Comment

              • rpnew
                New Member
                • Aug 2007
                • 189

                #8
                Originally posted by vikas1111
                I have created a table in mysql database to insert some records say students or employee records.. Now what i have to do is i have to display all the records in admin view page..( which i have done).. There is an option provided for editing the records beside every record.. So when the admin clicks on the edit button another form should open which will contain information of the user in the text box so that he can just edit and save the changes back into the databse..

                This is a part of what i have coded..

                [PHP]
                include("connec tion.php");
                $result = mysql_query("SE LECT * FROM usttable");
                while($row = mysql_fetch_arr ay($result))
                {
                echo "<input type="text" name="txtname" value='$row[\'id\']'>";
                }

                [/PHP]
                Hi,
                can you be a little more specific.. i guess i'm a bit confused with what you exactly want... i mean are you getting any error or you are asking how do i do that?

                Regards,
                RP

                Comment

                • vikas1111
                  New Member
                  • Feb 2008
                  • 122

                  #9
                  <input type="text" name="text1" value="<?php echo $row["usr_passwo rd"]; ?>">

                  This line I was searching for .....


                  THANKS

                  Comment

                  • rpnew
                    New Member
                    • Aug 2007
                    • 189

                    #10
                    Originally posted by vikas1111
                    <input type="text" name="text1" value="<?php echo $row["usr_passwo rd"]; ?>">

                    This line I was searching for .....


                    THANKS
                    welcome,
                    Glad that you found solution.
                    come back whenever you have problem.

                    Regards,
                    RP

                    Comment

                    • vikas1111
                      New Member
                      • Feb 2008
                      • 122

                      #11
                      Originally posted by rpnew
                      welcome,
                      Glad that you found solution.
                      come back whenever you have problem.

                      Regards,
                      RP

                      Sure RP Thanks once again..

                      Comment

                      Working...