0

I saved inputs from this form to another php page as variables. How can I get those variables to into a different page with <title>$title</title>.

Basically transfer variables from one page to another with the same info.

INDEX.HTML

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <form  action="action.php" method="POST">
      <p>Video Title</p>   <input type="text" name="title"> <br>
     <p>Video Link</p> <input type="text" name="Link"> <br>
     <p>Description</p> <input type="text" name="desc"> <br>
     <p>Page Name</p>   <input type="text" name="pagename"> <br>
      <input type="submit" value="Submit">
    </form>
  </body>
</html>

ACTION.PHP (Saved Variables)

$title = htmlspecialchars($_POST['title']);
$link = htmlspecialchars($_POST['link']);
$desc = htmlspecialchars($_POST['desc']);
$pgname = htmlspecialchars($_POST['pagename']);

VIDEO.PHP

    <title><?php  echo $_POST["$title"]; ?></title>

3 Answers3

1

Use $_SESSION to use the variables to another page

action.php
session_start();
$_SESSION['title']= htmlspecialchars($_POST['title']);
// all the other variables


video.php
session_start();
echo $_SESSION['title'];
Naresh Kumar
  • 561
  • 2
  • 15
1

This is one of the way you can do it, But $_SESSION is the best for doing this.

Action.php

$title = htmlspecialchars($_POST['title']);
$_GET['title'] = $title;

Video.php

<title><?php echo $_GET["title"]; ?></title>

If you interested on $_SESSION then, initialize / start the session in each page, set the session in action page and get the session from video page. for more: visit

Murad Hasan
  • 9,565
  • 2
  • 21
  • 42
0

Use Session Variables. Making sure to start a new session on each page.For example, if you want to transfer variables from action.php to video.php, do the following:

/* In Action.php*/
session_start();
$_SESSION['title']= htmlspecialchars($_POST['title']);
/*Do the same for the rest of variables */

/*In Video.php*/
session_start();
echo $_SESSION['title'];
/*Do the same for the rest of the variables you saved in the Session super global array in 'action.php'
Avi
  • 507
  • 3
  • 9
  • 26