phpbeginner Posted October 22, 2009 Share Posted October 22, 2009 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 Quote Link to comment Share on other sites More sharing options...
cags Posted October 22, 2009 Share Posted October 22, 2009 What is in filename.php? Is it just text you want to include on the page? If it is then in theory that method should work. Difficult to say without more information. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted October 22, 2009 Author Share Posted October 22, 2009 roomrates.php The textarea displays fine from the database but there is nothing to indicate the include file. When viewing source it shows up as <?php include('roomrates.php'); ?> Quote Link to comment Share on other sites More sharing options...
bestrong Posted October 22, 2009 Share Posted October 22, 2009 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> Quote Link to comment Share on other sites More sharing options...
cags Posted October 22, 2009 Share Posted October 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted October 22, 2009 Author Share Posted October 22, 2009 The textarea is a database field....... so it would be echo(" . $row['textarea'] . "); Quote Link to comment Share on other sites More sharing options...
cags Posted October 22, 2009 Share Posted October 22, 2009 Are you saying you wish to insert the contents of a file into a database field? If so you would need to use file_get_contents or similar to read the contents into a variable, then write that variable to the database. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted October 22, 2009 Author Share Posted October 22, 2009 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); ?> Quote Link to comment Share on other sites More sharing options...
cags Posted October 22, 2009 Share Posted October 22, 2009 What? Make your mind up do you want it in a HTML textarea or in the database? Your confusing the hell out of me. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted October 22, 2009 Author Share Posted October 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
cags Posted October 22, 2009 Share Posted October 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted October 22, 2009 Author Share Posted October 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
cags Posted October 22, 2009 Share Posted October 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted October 22, 2009 Author Share Posted October 22, 2009 roomrates.php is text fields from another database table. Just one table, with 4 fields. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted October 22, 2009 Author Share Posted October 22, 2009 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. Then the textarea field would not display. echo(" . $row['textarea'] . "); Quote Link to comment Share on other sites More sharing options...
cags Posted October 22, 2009 Share Posted October 22, 2009 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> Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted October 22, 2009 Author Share Posted October 22, 2009 Ya lost me but......thanks for helping. It's very simple what I want to do and I don't think what you posted is it. Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted October 22, 2009 Author Share Posted October 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
cags Posted October 22, 2009 Share Posted October 22, 2009 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']; } ?> Quote Link to comment Share on other sites More sharing options...
phpbeginner Posted October 22, 2009 Author Share Posted October 22, 2009 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? Quote Link to comment Share on other sites More sharing options...
purpleshadez Posted October 22, 2009 Share Posted October 22, 2009 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? 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. Quote Link to comment Share on other sites More sharing options...
cags Posted October 22, 2009 Share Posted October 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.