displaying data to form....

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dba

    displaying data to form....

    Have been displaying data from database using html for some time but
    just recently trying to display data back to "form". Can't find answer.

    <form method="post" action="<?php echo $PHP_SELF;?>">
    First Name:<input type="text" size="12" maxlength="12" name="Fname"><b r >
    Last Name:<input type="text" size="12" maxlength="36" name="Lname"><b r />
    Gender:<br />
    Male:<input type="radio" value="Male" name="gender">< br />
    Female:<input type="radio" value="Female" name="gender">< br />

    Now once I have the data in the database I want to display in the same
    form. Have been doing googles and have for some time been displaying
    using html like

    echo "Hello, ".$Fname." ".$Lname.". <br />";
    echo "You are ".$gender." , and you like ";

    but just lately realized I have never display in a "form".

    Any help will be appreciated.
  • Jerry Stuckle

    #2
    Re: displaying data to form....

    dba wrote:
    Have been displaying data from database using html for some time but
    just recently trying to display data back to "form". Can't find answer.
    >
    <form method="post" action="<?php echo $PHP_SELF;?>">
    First Name:<input type="text" size="12" maxlength="12" name="Fname"><b r >
    Last Name:<input type="text" size="12" maxlength="36" name="Lname"><b r />
    Gender:<br />
    Male:<input type="radio" value="Male" name="gender">< br />
    Female:<input type="radio" value="Female" name="gender">< br />
    >
    Now once I have the data in the database I want to display in the same
    form. Have been doing googles and have for some time been displaying
    using html like
    >
    echo "Hello, ".$Fname." ".$Lname.". <br />";
    echo "You are ".$gender." , and you like ";
    >
    but just lately realized I have never display in a "form".
    >
    Any help will be appreciated.
    >
    You need alt.html to find out how html works.

    Hint - the input field has a "value" attribute which contains the test
    you wish to display in it.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • chrisv

      #3
      Re: displaying data to form....

      On May 6, 7:44 pm, dba <some...@somepl ace.orgwrote:
      Have been displaying data from database using html for some time but
      just recently trying to display data back to "form". Can't find answer.
      >
      <form method="post" action="<?php echo $PHP_SELF;?>">
      First Name:<input type="text" size="12" maxlength="12" name="Fname"><b r >
      Last Name:<input type="text" size="12" maxlength="36" name="Lname"><b r />
      Gender:<br />
      Male:<input type="radio" value="Male" name="gender">< br />
      Female:<input type="radio" value="Female" name="gender">< br />
      >
      Now once I have the data in the database I want to display in the same
      form. Have been doing googles and have for some time been displaying
      using html like
      >
      echo "Hello, ".$Fname." ".$Lname.". <br />";
      echo "You are ".$gender." , and you like ";
      >
      but just lately realized I have never display in a "form".
      >
      Any help will be appreciated.
      Okay, I think I know what you are trying to do. You want to retrieve
      data from a db to populate entry options on a form that was initially
      used to enter the information. Here's sample code from one of my
      scripts to give you a good example on how to do this. This is for the
      select/options html element. You will have to do it differently for
      text areas, radio boxes, and others. But this snippet should get you
      on the right track:


      //run the query to get all data stored in the INTAKE 1 FORM for this
      id

      $query = "select * from intake1 where consumer_id = ".$id;
      $result = mysql_query($qu ery);
      if($row = mysql_fetch_arr ay($result)) {

      //there are many fields, but we are just using this one
      //for demonstration purposes

      $gender_form_en try = $row["gender_id"];
      }


      later on down the page i have this code for the gender section on the
      form
      <form>
      ....
      <td>
      <div class="formUnit Vertical">
      <label for="gender">Ge nder:</label>
      <br/>
      <select name="gender">
      <?php

      //get data entered in the gender table
      $genderQuery = "select * from lst_gender";
      $result = mysql_query($ge nderQuery);

      //take resultset and makeform vars
      while($row=mysq l_fetch_array($ result)) {

      $gender_id = $row["id"];
      $gender_type = $row["gender"];

      //see if there is a gender id stored for
      this form
      //associated with this consumer id
      if($gender_form _entry == $gender_id){

      //yes, there is an id stored for this
      form that matches
      //an id from the gender table, so mark
      it as SELECTED
      echo "<option value=\"".$gend er_id."\"
      selected>".$gen der_type."</option>";

      }else{

      //nothing stored in database, select
      nothing
      echo "<option value=\"".$gend er_id."\">".
      $gender_type."</option>";

      }
      }
      ?>
      </select>
      </div>
      </td>
      ....
      <input type='submit' />
      ...
      </form>


      hope this helps



      chris


      Comment

      • Gordon

        #4
        Re: displaying data to form....

        On May 7, 1:44 am, dba <some...@somepl ace.orgwrote:
        Have been displaying data from database using html for some time but
        just recently trying to display data back to "form". Can't find answer.
        >
        <form method="post" action="<?php echo $PHP_SELF;?>">
        First Name:<input type="text" size="12" maxlength="12" name="Fname"><b r >
        Last Name:<input type="text" size="12" maxlength="36" name="Lname"><b r />
        Gender:<br />
        Male:<input type="radio" value="Male" name="gender">< br />
        Female:<input type="radio" value="Female" name="gender">< br />
        >
        Now once I have the data in the database I want to display in the same
        form. Have been doing googles and have for some time been displaying
        using html like
        >
        echo "Hello, ".$Fname." ".$Lname.". <br />";
        echo "You are ".$gender." , and you like ";
        >
        but just lately realized I have never display in a "form".
        >
        Any help will be appreciated.
        <input type="text" name="inputFiel dName" value="<?php echo
        ($thisFieldValu e); ?>" />

        If the data contains characters that have special meaning in HTML such
        as < & etc then use htmlspecialchar s () to escape them.

        Textareas simply require you to do the echo between the <textareaand
        </textareatag.

        Now you know how to do inputs and textareas I'll leave selects,
        checkboxes and radio buttons as an exercise for the original poster.
        Hint: Select options have a "selected" attribute, checkboxes and
        radios have a "checked" attribute.

        Comment

        • dba

          #5
          Re: displaying data to form....

          Really?

          <input type="text" name="inputFiel dName" value="<?php echo
          ($thisFieldValu e); ?>" />

          Jerry Stuckle wrote:
          dba wrote:
          >Have been displaying data from database using html for some time but
          >just recently trying to display data back to "form". Can't find answer.
          >>
          ><form method="post" action="<?php echo $PHP_SELF;?>">
          >First Name:<input type="text" size="12" maxlength="12" name="Fname"><b r >
          >Last Name:<input type="text" size="12" maxlength="36" name="Lname"><b r />
          >Gender:<br />
          >Male:<input type="radio" value="Male" name="gender">< br />
          >Female:<inpu t type="radio" value="Female" name="gender">< br />
          >>
          >Now once I have the data in the database I want to display in the same
          >form. Have been doing googles and have for some time been displaying
          >using html like
          >>
          >echo "Hello, ".$Fname." ".$Lname.". <br />";
          >echo "You are ".$gender." , and you like ";
          >>
          >but just lately realized I have never display in a "form".
          >>
          >Any help will be appreciated.
          >>
          >
          You need alt.html to find out how html works.
          >
          Hint - the input field has a "value" attribute which contains the test
          you wish to display in it.
          >

          Comment

          • dba

            #6
            Re: displaying data to form....

            Thanks so much Chrisv and Gordon. That jogged my memory. I appreciate
            the help.

            Gordon wrote:
            On May 7, 1:44 am, dba <some...@somepl ace.orgwrote:
            >Have been displaying data from database using html for some time but
            >just recently trying to display data back to "form". Can't find answer.
            >>
            ><form method="post" action="<?php echo $PHP_SELF;?>">
            >First Name:<input type="text" size="12" maxlength="12" name="Fname"><b r >
            >Last Name:<input type="text" size="12" maxlength="36" name="Lname"><b r />
            >Gender:<br />
            >Male:<input type="radio" value="Male" name="gender">< br />
            >Female:<inpu t type="radio" value="Female" name="gender">< br />
            >>
            >Now once I have the data in the database I want to display in the same
            >form. Have been doing googles and have for some time been displaying
            >using html like
            >>
            >echo "Hello, ".$Fname." ".$Lname.". <br />";
            >echo "You are ".$gender." , and you like ";
            >>
            >but just lately realized I have never display in a "form".
            >>
            >Any help will be appreciated.
            >
            <input type="text" name="inputFiel dName" value="<?php echo
            ($thisFieldValu e); ?>" />
            >
            If the data contains characters that have special meaning in HTML such
            as < & etc then use htmlspecialchar s () to escape them.
            >
            Textareas simply require you to do the echo between the <textareaand
            </textareatag.
            >
            Now you know how to do inputs and textareas I'll leave selects,
            checkboxes and radio buttons as an exercise for the original poster.
            Hint: Select options have a "selected" attribute, checkboxes and
            radios have a "checked" attribute.

            Comment

            • dba

              #7
              Re: displaying data to form....

              chrisv,

              Jogged my memory and then a lot more. Thanks again.

              chrisv wrote:
              On May 6, 7:44 pm, dba <some...@somepl ace.orgwrote:
              >Have been displaying data from database using html for some time but
              >just recently trying to display data back to "form". Can't find answer.
              >>
              ><form method="post" action="<?php echo $PHP_SELF;?>">
              >First Name:<input type="text" size="12" maxlength="12" name="Fname"><b r >
              >Last Name:<input type="text" size="12" maxlength="36" name="Lname"><b r />
              >Gender:<br />
              >Male:<input type="radio" value="Male" name="gender">< br />
              >Female:<inpu t type="radio" value="Female" name="gender">< br />
              >>
              >Now once I have the data in the database I want to display in the same
              >form. Have been doing googles and have for some time been displaying
              >using html like
              >>
              >echo "Hello, ".$Fname." ".$Lname.". <br />";
              >echo "You are ".$gender." , and you like ";
              >>
              >but just lately realized I have never display in a "form".
              >>
              >Any help will be appreciated.
              >
              Okay, I think I know what you are trying to do. You want to retrieve
              data from a db to populate entry options on a form that was initially
              used to enter the information. Here's sample code from one of my
              scripts to give you a good example on how to do this. This is for the
              select/options html element. You will have to do it differently for
              text areas, radio boxes, and others. But this snippet should get you
              on the right track:
              >
              >
              //run the query to get all data stored in the INTAKE 1 FORM for this
              id
              >
              $query = "select * from intake1 where consumer_id = ".$id;
              $result = mysql_query($qu ery);
              if($row = mysql_fetch_arr ay($result)) {
              >
              //there are many fields, but we are just using this one
              //for demonstration purposes
              >
              $gender_form_en try = $row["gender_id"];
              }
              >
              >
              later on down the page i have this code for the gender section on the
              form
              <form>
              ...
              <td>
              <div class="formUnit Vertical">
              <label for="gender">Ge nder:</label>
              <br/>
              <select name="gender">
              <?php
              >
              //get data entered in the gender table
              $genderQuery = "select * from lst_gender";
              $result = mysql_query($ge nderQuery);
              >
              //take resultset and makeform vars
              while($row=mysq l_fetch_array($ result)) {
              >
              $gender_id = $row["id"];
              $gender_type = $row["gender"];
              >
              //see if there is a gender id stored for
              this form
              //associated with this consumer id
              if($gender_form _entry == $gender_id){
              >
              //yes, there is an id stored for this
              form that matches
              //an id from the gender table, so mark
              it as SELECTED
              echo "<option value=\"".$gend er_id."\"
              selected>".$gen der_type."</option>";
              >
              }else{
              >
              //nothing stored in database, select
              nothing
              echo "<option value=\"".$gend er_id."\">".
              $gender_type."</option>";
              >
              }
              }
              ?>
              </select>
              </div>
              </td>
              ...
              <input type='submit' />
              ..
              </form>
              >
              >
              hope this helps
              >
              >
              >
              chris
              >
              >

              Comment

              • Jerry Stuckle

                #8
                Re: displaying data to form....

                dba wrote:
                Really?
                >
                <input type="text" name="inputFiel dName" value="<?php echo
                ($thisFieldValu e); ?>" />
                >
                Jerry Stuckle wrote:
                >dba wrote:
                >>Have been displaying data from database using html for some time but
                >>just recently trying to display data back to "form". Can't find answer.
                >>>
                >><form method="post" action="<?php echo $PHP_SELF;?>">
                >>First Name:<input type="text" size="12" maxlength="12"
                >>name="Fname"> <br >
                >>Last Name:<input type="text" size="12" maxlength="36"
                >>name="Lname"> <br />
                >>Gender:<br />
                >>Male:<input type="radio" value="Male" name="gender">< br />
                >>Female:<inp ut type="radio" value="Female" name="gender">< br />
                >>>
                >>Now once I have the data in the database I want to display in the
                >>same form. Have been doing googles and have for some time been
                >>displaying using html like
                >>>
                >>echo "Hello, ".$Fname." ".$Lname.". <br />";
                >>echo "You are ".$gender." , and you like ";
                >>>
                >>but just lately realized I have never display in a "form".
                >>>
                >>Any help will be appreciated.
                >>>
                >>
                >You need alt.html to find out how html works.
                >>
                >Hint - the input field has a "value" attribute which contains the test
                >you wish to display in it.
                >>
                >
                Yes. "value" is an html attribute, not PHP code. Learn the difference.

                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • Jerry Stuckle

                  #9
                  Re: displaying data to form....

                  dba wrote:
                  Jerry Stuckle wrote:
                  >dba wrote:
                  >>Have been displaying data from database using html for some time but
                  >>just recently trying to display data back to "form". Can't find answer.
                  >>>
                  >><form method="post" action="<?php echo $PHP_SELF;?>">
                  >>First Name:<input type="text" size="12" maxlength="12"
                  >>name="Fname"> <br >
                  >>Last Name:<input type="text" size="12" maxlength="36"
                  >>name="Lname"> <br />
                  >>Gender:<br />
                  >>Male:<input type="radio" value="Male" name="gender">< br />
                  >>Female:<inp ut type="radio" value="Female" name="gender">< br />
                  >>>
                  >>Now once I have the data in the database I want to display in the
                  >>same form. Have been doing googles and have for some time been
                  >>displaying using html like
                  >>>
                  >>echo "Hello, ".$Fname." ".$Lname.". <br />";
                  >>echo "You are ".$gender." , and you like ";
                  >>>
                  >>but just lately realized I have never display in a "form".
                  >>>
                  >>Any help will be appreciated.
                  >>>
                  >>
                  >You need alt.html to find out how html works.
                  >>
                  >Hint - the input field has a "value" attribute which contains the test
                  >you wish to display in it.
                  >>
                  >
                  Really?
                  >
                  <input type="text" name="inputFiel dName" value="<?php echo
                  ($thisFieldValu e); ?>" />
                  >
                  Oh, and please don't top post. (Top posting fixed this time).

                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • dba

                    #10
                    Re: displaying data to form....

                    I understand retard. Perhaps you ought to find something else to do with
                    your time.

                    Also, we have gone over your "flat earth society" bottom post rant before.

                    NEVER


                    Jerry Stuckle wrote:
                    dba wrote:
                    >Really?
                    >>
                    ><input type="text" name="inputFiel dName" value="<?php echo
                    >($thisFieldVal ue); ?>" />
                    >>
                    >Jerry Stuckle wrote:
                    >>dba wrote:
                    >>>Have been displaying data from database using html for some time but
                    >>>just recently trying to display data back to "form". Can't find answer.
                    >>>>
                    >>><form method="post" action="<?php echo $PHP_SELF;?>">
                    >>>First Name:<input type="text" size="12" maxlength="12"
                    >>>name="Fname" ><br >
                    >>>Last Name:<input type="text" size="12" maxlength="36"
                    >>>name="Lname" ><br />
                    >>>Gender:<br />
                    >>>Male:<inpu t type="radio" value="Male" name="gender">< br />
                    >>>Female:<inpu t type="radio" value="Female" name="gender">< br />
                    >>>>
                    >>>Now once I have the data in the database I want to display in the
                    >>>same form. Have been doing googles and have for some time been
                    >>>displaying using html like
                    >>>>
                    >>>echo "Hello, ".$Fname." ".$Lname.". <br />";
                    >>>echo "You are ".$gender." , and you like ";
                    >>>>
                    >>>but just lately realized I have never display in a "form".
                    >>>>
                    >>>Any help will be appreciated.
                    >>>>
                    >>>
                    >>You need alt.html to find out how html works.
                    >>>
                    >>Hint - the input field has a "value" attribute which contains the
                    >>test you wish to display in it.
                    >>>
                    >>
                    >
                    Yes. "value" is an html attribute, not PHP code. Learn the difference.
                    >

                    Comment

                    • Rik Wasmus

                      #11
                      Re: displaying data to form....

                      On Wed, 07 May 2008 16:53:35 +0200, dba <someone@somepl ace.orgwrote:
                      I understand retard. Perhaps you ought to find something else to do with
                      your time.
                      Hmmmz, after he helped you?
                      Also, we have gone over your "flat earth society" bottom post rant
                      before.
                      Ah, so you do know you should bottom post allready?
                      1 & 1 = PLONK

                      Have a very pleasant life.
                      --
                      Rik Wasmus

                      Comment

                      • dba

                        #12
                        Re: displaying data to form....

                        Thanks for the thoughtful gesture. It is truly appreciated.

                        Rik Wasmus wrote:
                        On Wed, 07 May 2008 16:53:35 +0200, dba <someone@somepl ace.orgwrote:
                        >I understand retard. Perhaps you ought to find something else to do
                        >with your time.
                        >
                        Hmmmz, after he helped you?
                        >
                        >Also, we have gone over your "flat earth society" bottom post rant
                        >before.
                        >
                        Ah, so you do know you should bottom post allready?
                        1 & 1 = PLONK
                        >
                        Have a very pleasant life.

                        Comment

                        Working...