Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to use $_POST to change some contents forever

I am trying to populate data from a website to another wensite:
a.html:

<form action="b.php" method="post">
<textarea id="myProjects" name="mp"></textarea>
<input id="submit" type="submit" value="Submit" />
</form>

in b.php:

<?php $content=$_POST['mp'];
echo "you entered ".$content;
?>

This works in a very strange way, when I click submit button, I am directed to the b.php page, and I can see what I entered. But if I reload this page, not refresh, my contents disappear, and throwWarning: Undefined array key "mp" It looks like data received from $_POST is "temporarily" stored. I am new to PHP, so I am not sure how can I figure it out.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the PHP SESSION feature to keep the data persistent:

in b.php:

<?php
   // Start the session
   session_start();

   // save the input var as a SESSION property
   if (isset($_POST['mp'])) {
      $_SESSION['content'] = $_POST['mp'];
   }

   // display the property
   echo "you entered " . $_SESSION['content'];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading