Jump to content

I'm new to PHP, having trouble displaying data in a form


michael1062

Recommended Posts

Hi i'm new to PHP/web development but not new to coding.

 

I have some php code that I grabed from a template where I am selecting data from a file and having it diplay on the screen in a form.  My $query = "select * from file where" statement works and bring the data back to the screen.  However, I want the data to be returned in a textarea instead of a text field that is not big enough to display the 3 paragraph that i need to display. 

 

Please see code below, thsi code will return the data but the text box only returns the data in a line, I need the data to be returned in a textarea, so I can update it.  I have looked for the correct syntex with no luck, please correct me.

 

  $row = mysql_fetch_array($result, MYSQL_ASSOC);

  $recordid = $row['recordid'];

  $homepage = $row['homepage'];

 

  echo "<h2>Update About Us Information</h2>\n";

  echo "<form enctype=\"multipart/form-data\" action=\"admin.php\" method=\"post\">\n";

 

  echo "<table width=\"100%\" cellpadding=\"1\" border=\"1\">\n";

  echo "<tr><td><h3>Record ID</h3></td><td>$recordid</td></tr>\n";

 

  echo "<tr><td><h3>Homepage</h3></td><td><input type=\"text\" size=\"100\"  name=\"homepage\" value=\"$homepage\" /></td></tr>\n";

 

  echo "</table>\n";

 

  echo "<input type=\"submit\" name=\"button\" value=\"Update\">\n";

  echo "<input type=\"submit\" name=\"button\" value=\"Delete Product\">\n";

  echo "</form>\n";

Link to comment
Share on other sites

Hey there,

 

for future reference, be sure to place your code inside of [ code ][ /code ] (with no spaces on the inside of the tags) tags so its easy to read.

 

As for your example, why dont you change the the input type to 'textarea' instead of just 'text' ? You can then use either CSS to style in the appropriate height and width or you can use a format like this: <textarea rows="2" cols="20"> to get the proper height and width you need.

 

Hope that helped

 

algid

Link to comment
Share on other sites

Thanks algid, i have search high and low for a syntex on the correct way to use the "input" statement in php and I was unable to find an example where it used a type od textarea.  when I didi use the type of textarea there was no change to the grid is stilled appeared as a text box.

 

as far as the style sheet, that was something that i hadn't thought of and not sure how to use is.  I have coded in the midrange area for over 20 year but I am new to php and CSS, and not sure how to control with CSS.

 

Michael1062

Link to comment
Share on other sites

my apologies for the improper syntax there. The correct way to use textarea is as a tag, such as:

<input type="text" name="textName"/> <!--This is the single line entry -->

<textarea name="textareaName" rows="10" cols="10"><!-- Your variable that pulls in your 3 paragraphs would go here--> </textarea>

 

both of those above can be used within the form tags and will pull in the data using $_GET or $_POST variables.

 

Here is a link to the documentation for textarea:

http://www.w3schools.com/tags/tag_textarea.asp

 

and for input type text:

http://www.w3schools.com/tags/att_input_type.asp

 

I work with a lot of mixed HTML and PHP, but started off with HTML and CSS. CSS is waayy more reliable than working with table attributes and i really try to stay away from using tables, i stick with using DIV tags instead. of course depending on the use case.

 

Heres a quick tutorial on CSS as well in case you are interested:

http://www.w3schools.com/css/

 

hope this helps out!

 

algid

Link to comment
Share on other sites

Thank you, I will try to implement this change in hope that it will work.  I have actually tried to use the <textarea>  Tag,  But I assumed that I was doing something wrong because textarea shows up but is will not allow my data to be displayed in the box.  I was assuming that I was doing something wrong, thinking that textarea only allows input.  I need to display what is in the file already and then allow the user to update the data.  I will continue to look for a way to get the data into the textarea.  If u can see what I am doing wrong, please point it out.

 

This is the code that I used:

 

echo "<tr><td></td><td><textarea rows=\"10\" cols=\"50\"  name=\"homepage\" value=\"$homepage\"></textarea></td></tr><br>\n";

 

Thanks.

 

 

michael1062

 

Also I am new to this site, what is the answer to the question:

 

John, George, Paul and ....:

 

Link to comment
Share on other sites

Ok, here is a even better question, this is the code where I am trying to display the data in a textarea and the textarea box is blank but the paragraph is displayed outside of the textarea via the echo command just on the page.  I am sure there is a simple solution and I assume that it in my technique.  Please tell me a better way to retrieve data and place it in a textarea.

 

michael1062

18390_.php

Link to comment
Share on other sites

with other form input tags, the value attribute would usually place the content within that field. With the textbox however, this is not the case. You would place your content inside the tags like this:

//yours
echo "<tr><td></td><td><textarea rows=\"10\" cols=\"50\" name=\"homepage\" value=\'$homepag\'></textarea></td></tr><br>\n";

//mine
echo "<tr><td></td><td><textarea rows=\"10\" cols=\"50\" name=\"homepage\">$homepag</textarea></td></tr><br>\n";

 

the content to be edited will get placed inside the text box.

The content that is showing up before the text area is due to your

echo"$homepage<br><br>\n";

 

remove that and i would think everything should work fine. As far as your method of getting the data, there are other ways to access and get data from a database but an understanding of object oriented programming (OOP) would be needed as PHP's library has objects and classes set up to do just that. Here is an example:

 

http://php.net/manual/en/book.pdo.php

 

If OOP is hard to understand or you havent worked with it before then i would say stick with your current method.

 

algid

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.