Page 1 of 1

Newby Question: Passing contents of a textarea to a variable

Posted: Thu Mar 16, 2006 6:28 am
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.

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

Posted: Thu Mar 16, 2006 6:32 am
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'];

Thanks

Posted: Thu Mar 16, 2006 6:51 am
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.

Posted: Thu Mar 16, 2006 6:58 am
by Benjamin
I don't see $_POST['wiki_text'] in there anywhere. Post all your code.