-1

I have a text-area, in which I need some text.

I simply need to get that text to be echoed out with PHP, while on the same page

This is my code so far:

<body>
    <br>
    <h1>Charles Dickens</h1>
    <form action="Charles Dickens.php" method="GET">
        <hr/>
        <textarea rows="20" cols="100" name="textTest">This a is the text Testing area.</textarea>
        <hr/>
    </form>

    <br>
    <br>

    <?php 
        $textTest = $_GET['textTest'];
        echo $textTest;
    ?>

</body>

for some reason it's give me an "undefined error", though the variable is defined:

textTest is undefined.
LondonRob
  • 73,083
  • 37
  • 144
  • 201
Dice
  • 49
  • 8

3 Answers3

1

I suggest you to change your file name as well:

  • it should be without space or with hyphens

here you can like this, but you need to submit a form:

<?php
    if(isset($_GET["textTest"]){
    echo $_GET["textTest"];
    }
?>

If you don't want to submit form try it:

<script>
    $('#text-id').keypress(function() {
        var value = this.value;
        console.log(value);

    });
</script>
Ahmad Hassan
  • 371
  • 4
  • 22
  • @Progrock right – Ahmad Hassan Oct 10 '17 at 11:08
  • 2
    Word delination is useful. Filenames can contain spaces, spaces can be unsafe in URLS, use an encoded space to represent one. And underscores can also present usabliity issues - think interpreting an underlined link containing an underscore. – Progrock Oct 10 '17 at 11:14
0

you have to check if the get variable is still defined:

<?php
if(isset($_GET["textTest"]){
    echo $_GET["textTest"];
}
?>

or add ?textTest=the%20text to the uri ;)

Christian
  • 151
  • 1
  • 11
0

I cannot add a comment for this...

Try doing

var_dump($_GET['textTest'])

Also add what Ahmad Hassan said, as before you submit the form the varible is undefined

if(isset($_GET['textTest'])) { echo $_GET['textTest'] } 
Shaun Moore
  • 118
  • 9