Jr Sarath
Jr Sarath

Reputation: 13

How to save php form data for use it later

I have a simple html form along with some php codes in a index.php file, and my question is: how can I save that form data and use them in a diffrent page? Php code looks like this:

if(isset($_POST['submit'])){
    //collect form data
    $name = $_POST['name'];
    $email = $_POST['email'];
}

HTML code looks like this:

<form action='' method='post'>
    <p><label>Name</label><br><input type='text' name='name' value=''></p> 
    <p><label>Email</label><br><input type='text' name='email' value=''></p> 
    <p><input type='submit' name='submit' value='Submit'></p> 
</form>

Upvotes: 0

Views: 6475

Answers (3)

JuanjoC
JuanjoC

Reputation: 195

I don´t know if this is what you want, since you dont specify, but you could save it via cookies with javascript, and then capture it with php.

JAVASCRIPT

       //Call this in the html
         function Example(element){

        var name = $(elemt).find('name').text();
        document.cookie = escape('variable') + '=' + escape(name) + '' +  '; path=/';

PHP

      $name= $_COOKIE['variable']))

Upvotes: 1

Simplest solution is save this data in session but this have a limitation to browser close time and it's only assigned to current browser session:

<?php
session_start();

if(isset($_POST['submit'])){
    //collect form data
    $_SESSION['name'] = $_POST['name'];
    $_SESSION['email'] = $_POST['email'];
}

echo $_SESSION['name'];
echo $_SESSION['email'];

?>

For better solution read this solutions and their limitations:

Session - http://php.net/manual/en/reserved.variables.session.php

File - http://php.net/manual/en/ref.filesystem.php

Database - https://www.w3schools.com/php/php_mysql_intro.asp

Upvotes: 3

Jayant Pandey
Jayant Pandey

Reputation: 110

you can save in session like below code

<?php

session start();
$_SESSION['postdata'] = $_POST;
?>

Upvotes: 1

Related Questions