Newby Question: Passing contents of a textarea to a variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andys22
Forum Newbie
Posts: 7
Joined: Wed Mar 15, 2006 10:01 am

Newby Question: Passing contents of a textarea to a variable

Post by andys22 »

Hi, I am trying to pass the contents of a textarea of my html form to a php string variable however I am not sure how to do this. I have tried commands such as:

Code: Select all

$newdata=wiki_text;
       $newdata=$HTTP_POST_VARS['wiki_text'];
However this is not working. I am sure that you can do it with a simple piece of code. Can anyone help me out please?

Thanks,

Andy.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Newby Question: Passing contents of a textarea to a vari

Post by Benjamin »

andys22 wrote:Hi, I am trying to pass the contents of a textarea of my html form to a php string variable however I am not sure how to do this. I have tried commands such as:

Code: Select all

$newdata=wiki_text;
       $newdata=$HTTP_POST_VARS['wiki_text'];
However this is not working. I am sure that you can do it with a simple piece of code. Can anyone help me out please?

Thanks,

Andy.
Well here..

Code: Select all

<textarea name="wiki_text"></textarea>

Code: Select all

$wiki_text = $_POST['wiki_text'];
andys22
Forum Newbie
Posts: 7
Joined: Wed Mar 15, 2006 10:01 am

Thanks

Post by andys22 »

That code seems to get the text into the variable however I am still having a problem hopefully you will be able to help me out with.

When I click submit on my form the variable $wiki_text is not being passed.

Code: Select all

<?php
    $filename = "wiki.data";
    // Open the file for truncated writing 
    $fp = fopen($filename, "w") or die("Couldn't open file for writing"); 
    $numBytes = fwrite($fp, $wiki_text) or die("Couldn't write values to file!"); 

    fclose($fp); 
  echo "Wrote $numBytes bytes to wiki.data successfully!";
  ?>
This php cose is in another file. will the variable get lost and therfore I should include some code here to get the text into the variable?

Thanks.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I don't see $_POST['wiki_text'] in there anywhere. Post all your code.
Post Reply