Jump to content

Loading data into textarea from mySQL


scarlson

Recommended Posts

Currently I have my users logging into my site and what I am wanting is to check to see if they have a form already filled out or if not, they need to fill out the form.  They are directed to one area where I am doing the check to see if they have this form already filled out and if so, then it will pre-load all the data in the fields (6 text boxes and 34 textarea boxes - some of the textarea boxes might be filled in but doesn't have to).  The user can then edit the textarea boxes and submit this and update the database.  If this is the first time, they will fill out what they want and insert into the database.

 

My question is:  I have already hard-coded the form so what do I need to do to pre-load all of these textarea boxes?  I have each textarea box named the same as the field name in the database already.  Would I store all the info in an array and then do a IF loop to load all the data in the textarea boxes?  Any examples or suggestions would be great. 

 

Thanks,

 

Scott

Link to comment
Share on other sites

it's usually done like this:

<text area name="somename" value="<?php print $userinput; ?>">

 

does that answer your question?

 

The textarea input type does not have a syntax acceptable even close to that

its

<textarea name="somename">
//The stuff in the box here
</textarea>

but yes you just echo it in the body just like you are echoing it out normally

Link to comment
Share on other sites

Ok I understand what I need to do but......  Here is a small sample of my form that I have:

 

<form id="setup" name="setup" method="post" action="data_setup.php">
    
    
    <table width="200" border="1" bordercolor="#000000">
      <caption>
        Account Information
      </caption>
      
      <tr>
        <td>
            <label>First Name
              <input type="text" name="fName" id="fName" />
              </label>
          
          </td>
        <td>
            <label>Last Name
              <input type="text" name="lName" id="lName" />
              </label>
     
          </td>
        <td>
            <label>Address
              <input type="text" name="address" id="address" />
              </label>
         
          </td>
        <td>
            <label>Zip Code
              <input type="text" name="zip" id="zip" />
              </label>
         
          </td>

 

There is a lot more to this.  Will I need to do a "IF" loop with the exact same code in each one but one pre-loaded with my data if they have filled this out before?

 

Something like:

If ($seller_id_rows == 1){    //tells me that the user has setup form already
//create my full form with pre-loaded data and a submit button to UPDATE database

}

else {
//create my full form with blank data fields with a submit button to INSERT INTO database
}

 

Does this seem like the right place to start at?

 

Link to comment
Share on other sites

you've got somewhat of the right idea. in my opinion, you should use $_SESSIONs to determine if a user has submitted a form instead of relying on $_POST. since $_POST is handled on the browser-side, there's no real way to tell if a user has submitted a form once, or more than once, for instance:

if (isset($_POST)) {

 

so you should use sessions since your data is being transferred to another page (data_setup.php). this way you can save information and use it from page to page. at least, that's what i do with form validation/handling.

Link to comment
Share on other sites

you've got somewhat of the right idea. in my opinion, you should use $_SESSIONs to determine if a user has submitted a form instead of relying on $_POST. since $_POST is handled on the browser-side, there's no real way to tell if a user has submitted a form once, or more than once, for instance:

if (isset($_POST)) {

 

so you should use sessions since your data is being transferred to another page (data_setup.php). this way you can save information and use it from page to page. at least, that's what i do with form validation/handling.

 

I am using SESSIONS to determine if the user is logged in already and if not sent back to the login page.  So I know that I have a logged in user, but a brand new user or one who is there to edit their items might show up so I need a way to handle each scenario.  That is why I was thinking of the IF/ELSE to do this.  I will know if the user has already been there before because a value from the my login table will be set in 2 other tables already, which I will check for.

 

I will just keep plugging away on this.  I will post some of my code tonight if I haven't gotten it figured out yet.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.