Question

I have file1.php and file2.php. In file1.php I have made a form for adding news articles and when I press button "Submit" the entered data is sent to MYSQL base and page redirects to file2.php. What I want to do is to display this article in file2.php. How can I do that?

Was it helpful?

Solution

You have to use session for this purpose.As you not posted your code here so i am posting a sample.Let say this is your code.For more help.Check these links.1,2,3.

file1.php

  <?php
  session_start();
  if(isset($_POST['article']))
  {
  //Then you add here in your MySQL
  //Similarly add them in the session so you can access the same data on your file2.php
    $_SESSION['article'] = $_POST['article'];

  //now redirect to file2.php
  }
  ?>

 <form action="#" method="POST">

 Article :<input type="text" name="article"/>

 <input type="submit" value="click"/>
 </form>

file2.php

 session_start();
 if(isset($_SESSION['article']))
 {
      echo $_SESSION['article'];
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top