All the values are stored in the $_POST collection
<?php print_r($_POST); ?>
or if you want something fancier that is easier to read use a foreach loop to loop through the $_POST collection and print the values.
<table>
<?php
foreach ($_POST as $key => $value) {
echo "<tr>";
echo "<td>";
echo $key;
echo "</td>";
echo "<td>";
echo $value;
echo "</td>";
echo "</tr>";
}
?>
</table>
Answer from Jared on Stack OverflowAll the values are stored in the $_POST collection
<?php print_r($_POST); ?>
or if you want something fancier that is easier to read use a foreach loop to loop through the $_POST collection and print the values.
<table>
<?php
foreach ($_POST as $key => $value) {
echo "<tr>";
echo "<td>";
echo $key;
echo "</td>";
echo "<td>";
echo $value;
echo "</td>";
echo "</tr>";
}
?>
</table>
You could try var_dump:
var_dump($_POST)
PHP: Echoing an input submitted from a form
Why is my HTML/PHP form echoing the PHP file and using get when post is specified? - Stack Overflow
php - echo form data? - Stack Overflow
forms - PHP: Possible to automatically get all POSTed data? - Stack Overflow
You do a submit and onclick. That goes wrong. Further, don't do a document.write!
Do this as better alternative (no php in js):
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') // check if post
echo htmlentities($_POST['tweet1']);
?>
<form method="post">
<input type="text" name="tweet1">
<br>
<input type="submit" value="Tweet!">
</form>
Rather than use javascript to write the content which, in your example wouldn't work, use php to generate the response for the user to see
<form method = "POST">
<input type = "text" name = "tweet1">
<br>
<input type = "submit" value='Submit' />
<div id='msgs'>
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' && isset( $_POST['tweet1'] ) ){
echo $_POST['tweet1'];
}
?>
</div>
</form>
try this using session ,
<? ob_start();
session_start();?>
<?php
// GET ACCOUNT INFORMATION FROM FORM AND ASSIGN VARIABLES
$first_name = $_SESSION['first_name'];
$last_name = $_SESSION['last_name'];
$email = $_SESSION['email'];
?>
<?php
/*
// ECHO ACCOUNT INFORMATION
echo "<strong> Account Information: </strong>";
echo "<br />";
echo First Name: ";
echo "<br />";
echo $first_name;
echo "<br />";
echo "<br />";
echo "Last Name: ";
echo "<br />";
echo $last_name;
echo "<br />";
echo "<br />";
echo "Email: ";
echo "<br />";
echo $email;
echo "<br />";
echo "<br />";
*/
?>
<?php
////// SEND TO DATABASE
/////////////////////////////////////////////////////////
// Database Constants
define("DB_SERVER", "#######");
define("DB_USER", "######");
define("DB_PASS", "");
define("DB_NAME", "######");
// 1. Create a database connection
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
die("Database connection failed: " . mysql_error());
}
// 2. Select a database to use
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
//////////////////////////////////////////////////////////////
$query="INSERT INTO registrations (Id,
first_name,
last_name,
email
)
VALUES('NULL',
'".$first_name."',
'".$last_name."',
'".$email."'
)";
mysql_query($query) or die ('Error updating database');
?>
<?php
function confirm_query($result_set) {
if (!$result_set) {
die("Database query failed: " . mysql_error());
}
}
function get_user_id() {
global $connection;
global $email;
$query = "SELECT *
FROM registrations
WHERE email = \"$email\"
";
$user_id_set = mysql_query($query, $connection);
confirm_query($user_id_set);
return $user_id_set;
}
?>
<?php
$user_id_set = get_user_id();
while ($user_id = mysql_fetch_array($user_id_set)) {
$cookie1 = "{$user_id["id"]}";
setcookie("registrations", $cookie1, time()+3600); /* expire in 1 hour */
}
?>
<? ob_flush(); ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Register</title>
<!-- The stylesheet -->
<link rel="stylesheet" href="assets/css/styles.css" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div id="main">
<h2>Step 2: Security Details</h2>
<br/>
<form class="" method="post" action="register_p3.php">
<div class="row date_of_birth">
<input type="text" id="date_of_birth" name="date_of_birth" placeholder="D.O.B 10/02/1990" />
</div>
<div class="row password">
<input type="password" id="password" name="password" placeholder="Password" />
</div>
<div class="row password2">
<input type="password" id="password2" name="password2" placeholder="Password (Confirm)" />
</div>
<input type="submit" value="Next >" />
</form>
</div>
<!-- JavaScript includes - jQuery, the complexify plugin and our own script.js -->
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="assets/js/jquery.complexify.js"></script>
<script src="assets/js/script.js"></script>
</body>
</html>
If you want information to be available on more than one page you should store it in a session. Just do something like this when you store the $_POST values into variables, and be sure to put a session_start(); call at the top of your page.
<?php
session_start();
// other php code here
$_SESSION['first_name'] = $first_name;
$_SESSION['last_name'] = $last_name;
$_SESSION['email'] = $email;
?>
Then you could access them on any page by calling $_SESSION['first_name'] or whatever variable you want to access. Just be sure to include session_start(); at the top of every page that requires using these variables.
Sure. Just walk through the $_POST array:
foreach ($_POST as $key => $value) {
echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";
}
No one mentioned Raw Post Data, but it's good to know, if posted data has no key, but only value, use Raw Post Data:
$postdata = file_get_contents("php://input");
PHP Man:
php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATA is not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype="multipart/form-data".
You are echoing the text box and at the same time hoping to gets its value, which is not possible.
echo '<input name="textfield" type="text" id="textfield" value="Roger" />';
echo 'Hello, '.$_POST['textfield'].'<br>';
You need to first submit the form with method set to post and only then you can get its value.
Example:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
...
<input name="textfield" type="text" id="textfield" value="Roger" />
...
<input name="submit" type="submit" id="submit" value="submit" />
</form>
PHP
if (isset($_POST['submit']))
{
echo 'Hello, '.$_POST['textfield'].'<br>';
}
Try print_r($_POST) or var_dump($_POST) to see if any POST data gets submitted.
Edit: Did you specify POST as the submit method in your form tag? Do you submit the form? Please show the entire <form>-Tag.