Reputation: 13
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
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
Reputation: 756
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
Reputation: 110
you can save in session like below code
<?php
session start();
$_SESSION['postdata'] = $_POST;
?>
Upvotes: 1