Jump to content

Using an include file in textarea


phpbeginner

Recommended Posts

I have a textarea that I use to edit the content of a page. Within the text on that page I am trying to insert an include file between paragraphs that I want it to display.....is this possible to get the include file to also display?

 

EX: My textarea is this.....

 

Text text text

 

Text text text

 

I tried this but it does not display.....

 

Text text text

<?php include ('filename.php'); ?>

Text text text

 

 

Link to comment
Share on other sites

Hmm, it is difficult to understand exactly what you are trying to do.

 

As I understand it, you have a page with an HTML <textarea></textarea> in a form.

 

Are you trying to edit the HTML content of another page with this textarea?

 

 

or are you trying to output this?

 

<form>
<textarea>
Text
Text
<?php include('roomrates.php'); ?>
Text
</textarea>
</form>

 

 

 

 

Link to comment
Share on other sites

What exactly does your code look like? An example of including information into a textarea.

 

main.php

<textarea name="text">
Blah, blah, blah.
<?php include 'include.php'; ?>
Blah, blah....
</textarea>

 

include.php

This is just some text I want in the box.

 

Link to comment
Share on other sites

Yes, exactly.......so in the textarea on the form I am submitting to update the database, rather than use....

 

<?php include('roomrates.php'); ?> where I want it to display in the textarea......

 

I would use

<?php $roomrates = file_get_contents('roomrates.php', FILE_USE_INCLUDE_PATH); ?>

Link to comment
Share on other sites

Sorry your confused...

 

I have a textarea used for submitting text to the database (I think has been mentioned). I want info from an include file to display in that also (I think this was mentioned).

 

For another example:

 

<textarea> Hello this is text. This is more text. Holy crap I think it is an include file coming up <?php include('roomrates.php'); ?> and more text </textarea>

 

Now when I echo the results of my textarea field I also want to display the info included in the php include file.

Link to comment
Share on other sites

Yes you did mention those things, but at no point have you coherently explained your problem. The important factors are what the content of roomrates.php looks like (I think has been mentioned) and what does a database have to do with it?

 

The example you just gave is essentially the exact code that bestrong and myself gave earlier. It is a piece of script that will display in a textarea of the viewers browser the contents of roommates.php surrounded by some pieces of text. If you then wanted to place this in a database you would use the exact method you would use if the include statement wasn't used.

 

$data = $_POST['name_of_textarea'];

INSERT INTO table (textarea) VALUES ('$data')

 

IF the roommates.php file contains anything but plain text and you wish that contents to be entered into the database then you will need to use the file_get_contents method as I also described.

 

<textarea name="text">
Blah, blah, blah.
<?php echo file_get_contents('roomrates.php'); ?>
Blah, blah....
</textarea>

 

But again depending on the contents this will probably break the HTML so you would need to use something like htmlentities to stop that happening.

 

If the overall objective is to insert HTML that will work again though that is something else to bare in mind.

Link to comment
Share on other sites

Still no go.......

 

In my database it shows all the text and then <?php echo file_get_contents('roomrates.php'); ?> and then more text.

 

When I am displaying the results on the page that end user sees it simply displays the text. When viewing the page source it shows all the text and then <?php echo file_get_contents('roomrates.php'); ?>  where I added it.

 

 

Link to comment
Share on other sites

Yet again you've not mentioned what the contents of roomrates.php is... *sigh* nevermind.

 

What is the file extension of the file you have the words <?php echo file_get_contents('roomrates.php'); ?>. If it is not .php your server is potentially not parsing it as PHP and thus you will just see the PHP code. If it is .php but your server doesn't have PHP enabled same thing applies.

Link to comment
Share on other sites

So you are saying that there is some kind of database search in roommates.php and you wish to include the information fetched from the database in the text area? That's simple.

 

<?php include 'roomrates.php'; ?>
<textarea name="text">
Blah, blah, blah.
<?php echo $variable_that_is_created_in_roomrates.php_containing_relevant_information; ?>
Blah, blah....
</textarea>

Link to comment
Share on other sites

underneath the text area and it works fine.

 

Another example:

 

echo('$row['textarea']); 

 

outputs text from that table....

and more text and more text.

 

I can then use

<?php include('roomrates'); ?>

underneath the text or over the text and all displays fine but I want to have this display within the textarea.

 

outputs text from that table....

<?php include('roomrates'); ?>

and more text and more text.

 

Link to comment
Share on other sites

Most likely because you don't appear to have a strong grasp of the language and seem unable to articulate with any great accuracy exactly what you are attempting to do. This is my current best guess at what your attempting to do. If thats not right I give up trying to understand you.

 

main.php

<?php include 'include.php'; ?>
<textarea name="text">
Blah, blah, blah.
<?php echo $items; ?>
Blah, blah....
</textarea>

 

include.php

<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('my_db');
$sql = "SELECT * FROM table";
$result = mysql_query($sql);
$items = "";
while($row = mysql_fetch_assoc($result)) {
   $items .= $row['textarea'];
}
?>

 

Link to comment
Share on other sites

Most likely because you don't appear to have a strong grasp of the language and seem unable to articulate with any great accuracy exactly what you are attempting to do. This is my current best guess at what your attempting to do. If thats not right I give up trying to understand you.

 

main.php

<?php include 'include.php'; ?>
<textarea name="text">
Blah, blah, blah.
<?php echo $items; ?>
Blah, blah....
</textarea>

 

include.php

<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('my_db');
$sql = "SELECT * FROM table";
$result = mysql_query($sql);
$items = "";
while($row = mysql_fetch_assoc($result)) {
   $items .= $row['textarea'];
}
?>

 

 

Nope......and with the examples I gave and the responses you have, I would assume that you are way to intelligent for this simple question from this simple person. Were you always so articulate? Do you hang around forums alot waiting for those not at your level of expertise, to keep mentioning throughout threads how knowledgeable you are and others aren't?

Link to comment
Share on other sites

Most likely because you don't appear to have a strong grasp of the language and seem unable to articulate with any great accuracy exactly what you are attempting to do. This is my current best guess at what your attempting to do. If thats not right I give up trying to understand you.

 

main.php

<?php include 'include.php'; ?>
<textarea name="text">
Blah, blah, blah.
<?php echo $items; ?>
Blah, blah....
</textarea>

 

include.php

<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('my_db');
$sql = "SELECT * FROM table";
$result = mysql_query($sql);
$items = "";
while($row = mysql_fetch_assoc($result)) {
   $items .= $row['textarea'];
}
?>

 

 

Nope......and with the examples I gave and the responses you have, I would assume that you are way to intelligent for this simple question from this simple person. Were you always so articulate? Do you hang around forums alot waiting for those not at your level of expertise, to keep mentioning throughout threads how knowledgeable you are and others aren't?

:wtf: heres an idea, post ALL the relevant code!!!

 

I have read this from start to finish and I'm also not sure I follow what you are going on about.

 

But I'll give it a shot. Are you typing the statement into the textarea box, then saving it to the database in hope that it will be sparsed on a different page which runs a query to get said data from database and display it on another page? kinda like a blog but one that lets you run php code? If so then what is the database query you are using to both store this data and then retrieve it again? Please be sure to include any and all sanitation & validation you are using to store and retrieve the data in the database.

 

Link to comment
Share on other sites

I'm not especially knowledgeable in comparison to many of the members around here and at no point in this thread have I said that I was. The simple fact is that you have tried to describe what your attempting multiple times. From the descriptions you've given you could be describing 20 differen't things. I've tried to ask questions to confirm what you are trying todo, infact I asked what the contents of roomrates.php looks like several times. The only answers which I received seem vague at best. When I say what exactly does the code look like a reply of "echo(" . $row['textarea'] . ");" and a description saying something about a database doesn't exactly clarify the matter.

 

Was I always this articulate? Well that depends on your definition of 'this'. I wouldn't consider myself especially articulate, infact quite the opposite as I had to have speach therapy as a child. I just take time to read what I've written several times and try to make sure I include enough relevant information.

 

By the tone of your post you seem to have taken offence. It was not my intention to offend, I just don't understand what you want.

 

I hope you find a solution. Good luck.

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.