i am trying to post the some data on another page at this i have a back button onclick of back button i wanna reload the original page with posted data.
use $_SESSION:
Page1.php
<?php
session_start();
$name = isset($_SESSION['name']) ? $_SESSION['name'] : '';
?>
<html>
<form method="post" action="Page2.php">
<input type="text" name="name" value="<?php echo $name; ?>" />
<input type="submit" value="Submit" />
</form>
</html>
Page2.php
<?php
session_start();
if (isset($_POST['name']))
{
$_SESSION['name'] = $_POST['name'];
}
$name = $_SESSION['name'];
?>
<html>
<form>
<span><?php echo $name; ?>" </span>
Back
</form>
</html>
you can use $_SESSION
<?php
if (!isset($_SESSION)) session_start();
if ($_POST['btnsubmit']){
$_SESSION['data1'] = $_POST['data1'];
$_SESSION['data2'] = $_POST['data2'];
$_SESSION['data3'] = $_POST['data3'];
//... and so on
}
?>
<form>
<input type="text" id="data1" value="<? echo $_SESSION['data1'];?>"/>
<input type="text" id="data2" value="<? echo $_SESSION['data2'];?>"/>
<input type="text" id="data3" value="<? echo $_SESSION['data3'];?>"/>
<input type="submit" id="btnsubmit" value="Submit"/>
</form>
<!-- and so on -->
Hope this gives you an idea
Related
I'm stuck at one point .I have a php form and after filling all details, user have to press submit button . If data does not submitted properly then I am reloading the page .
so My question is .
I want to set all previous values entered by user into respected
fields without request method.
how can i achieve this?
What I have done so far
My user.php
<?php
$name = '';
if(isset($_REQUEST[name]))
{
$name = $_REQUEST[name];
}
if(isset($_POST["submit"]))
{
$name = $_POST["txtname"];
header('Location:user.php?name=<?php echo $name; ?>');
}
?>
<hrml>
<body>
<form name="form1" id="form1" method="POST">
<label>Name:</label>
<input type="text" name="txtname" id="txtname" value="<?php echo $name; ?>">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
EDIT
apply_now.php
<?php
$CLASS__BL = 'apply_now_bl';
require_once('apply_now_bl.php');
?>
<form name="form1" id="form1" action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="input-label">Full Name: *</label>
<input name="txtname" id="txtname" type="text" class="form-control" value="<?= #$page_bl->full_name; ?>">
</div>
</form>
apply_now_bl.php
<?php
require_once('admin/db_lib/candidates.php');
require_once('includes/general_include.php');
$page_bl = apply_now_bl();
page_load();
class apply_now_bl
{
var $full_name = '';
function page_load()
{
$this->obj_candidates = new candidates();
if(isset($_POST["submit"]))
{
$this->submit_data();
}
}
function submit_data()
{
$this->full_name = get_post_val("txtname");
$this->obj_candidates->full_name = $this->full_name;
redirect(apply_now.php); //common function for page redirect
}
}
No need to redirect through php header location . because action is blank and that means it will redirect to user.php(current page) once form submit.
so below is the updated code
<?php
$name = "";
if (isset($_POST["submit"])) {
$name = $_POST["txtname"];
}
?>
<html>
<body>
<form name="form1" id="form1" method="POST">
<label>Name:</label>
<input type="text" name="txtname" id="txtname" value="<?php echo $name; ?>">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
Here is the code, it is telling me I have an undefined index which is weird because I already defined it with HTML code. Any way around this error? or any ways to make it better would be much appreciated...
<h1>make a username</h1>
<form method="post" action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
Username: <input type="text" name="username" value="<?php echo $username; ?>">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
$username = $_POST["username"];
echo $username;
?>
$_POST["username"] will only be defined after you submit the form. When you first load the page (with an http GET), $_POST["username"] will be undefined.
After form submission it will work. You should try this:
<?php
if(isset($_POST["username"])){
$username = $_POST["username"];
}
?>
<h1>make a username</h1>
<form method="post" action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
Username: <input type="text" name="username" value="<?php echo (isset($username))? $username: ''; ?>">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
echo (isset($username))? $username: '';
?>
Do following changes to your code :
<h1>make a username</h1>
<form method="post" action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
Username: <input type="text" name="username" value="<?php echo $username; ?>">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
/// This portion of code will execute only after you hit submit button
if(isset($_POST['username']))
{
$username = $_POST["username"];
echo $username;
}
?>
if ( isset( $_POST["username"] ) ){
$username = $_POST["username"];
} else{
$username = '';
}
echo $username;
Try this code instead of your php code. This may help you.
$_POST["username"];
add an # before this,#$_POST['username'],'#' will ignore this error
I have a problem on getting the session variables to work on different pages
I have three php scripts
1. index.php (includes a html form)
<?php
session_start();
if (isset($_POST['submit'])) {
$_SESSION['billTo_email'] = $_POST['billTo_email'];
}
?>
<form id = 'form_submit' method="post" action = "NetworkOnline.php">
<td><input type="text" name="billTo_email" id="f_name2" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit"/></td>
</form>
?>
NetworkOnline.php
<?php
session_start();
$_SESSION['billTo_email'] = $_POST["billTo_email"];
?>
$f_name=$_POST["f_name"];
$l_name=$_POST["l_name"];
$billTo_country=$_POST["billTo_country"];
$billTo_city=$_POST["billTo_city"];
$billTo_state=$_POST["billTo_state"];
$billTo_street1=$_POST["billTo_street1"];
$billTo_pin=$_POST["billTo_pin"];
$billTo_email = $_SESSION["billTo_email"];
response.php
<?php
session_start();
$_SESSION["billTo_email"] = $_POST["billTo_email"];
?>
<form name = "form1" method = "post" action="mail.php" >
<input type="hidden" name="order" id="order" value="<?php echo $order ?>" >
<input type="hidden" name="bank" id="bank" value="<?php echo $bank ?>" >
<input type="hidden" name="amount" id="amount" value="<?php echo $amount ?>" >
<input type = "test" name= "email" id ="email" value= "<?php echo $billTo_email ?>">
<input type="submit" id="submit" value="submit" name="submit">
</form>
Try this,
index.php:
<html>
<form id = 'form_submit' method="post" action = "NetworkOnline.php">
<td><input type="text" name="billTo_email" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit"/></td>
</form>
</html>
NetworkOnline.php:
<?php
session_start();
$_SESSION['billTo_email'] = $_POST["billTo_email"];
header('Location: response.php');
?>
response.php:
<?php
session_start();
$billTo_email=$_SESSION["billTo_email"]
?>
<form name = "form1" method = "post" action="mail.php" >
<br />
<br />
<input type = "test" name= "email" value= "<?php echo $billTo_email ?>">
<input type="submit" id="submit" value="submit" name="submit">
</form>
Try below,
Your closing tags are wrong in place,
index.php
<?php
session_start();
if (isset($_POST['submit'])) {
$_SESSION['billTo_email'] = $_POST['billTo_email'];
}
?>
<form id = 'form_submit' method="post" action = "NetworkOnline.php">
<td><input type="text" name="billTo_email" id="f_name2" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit"/></td>
</form>
NetworkOnline.php
<?php
session_start();
$_SESSION['billTo_email'] = $_POST["billTo_email"];
$f_name=$_POST["f_name"];
$l_name=$_POST["l_name"];
$billTo_country=$_POST["billTo_country"];
$billTo_city=$_POST["billTo_city"];
$billTo_state=$_POST["billTo_state"];
$billTo_street1=$_POST["billTo_street1"];
$billTo_pin=$_POST["billTo_pin"];
$billTo_email = $_SESSION["billTo_email"];
?>
response.php
<?php
session_start();
$_SESSION["billTo_email"] = $_POST["billTo_email"];
?>
<form name = "form1" method = "post" action="mail.php" >
<input type="hidden" name="order" id="order" value="<?php echo $order; ?>" >
<input type="hidden" name="bank" id="bank" value="<?php echo $bank; ?>" >
<input type="hidden" name="amount" id="amount" value="<?php echo $amount; ?>" >
<input type = "test" name= "email" id ="email" value= "<?php echo $billTo_email; ?>">
<input type="submit" id="submit" value="submit" name="submit">
</form>
UPDATE:
your index.php
<form id = 'form_submit' method="post" action = "NetworkOnline.php">
<td><input type="text" name="billTo_email" id="f_name2" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit"/></td>
</form>
NOTE: NO need to check if (isset($_POST['submit'])) { ... } here, because index.php send data to NetworkOnline.php.
Your NetworkOnline.php:
<?php
ob_start(); // turn on output buffering
session_start();
if( isset( $_POST['billTo_email'] ) ) { // work only if **billTo_email** has some value
$_SESSION['billTo_email'] = $_POST["billTo_email"];
}
// ?> <-- remove this closing tag
$f_name=$_POST["f_name"]; // this line of code shows undefined variable,
//because in your index.php there is no any f_name field presnet.
// your remaining codes
?>
I want to pass the value of input field address to php. So that when i click on submit button it will be store in php.
<input type="text" name="address">
<input type="submit" name="go" method="post">
<?php
if($_POST){
if(isset($_POST['go'])){
call();
}else{
echo "Error";
}
}
function call(){
echo "hi";
print(document.address.value);
}
?>
However when i click on button it response nothing.
You are mixing PHP and JavaScript. If you want a pure PHP solution you could do something like:
<?php
if(isset($_POST['go'])){
$address = $_POST['address'];
echo $address;
}
?>
<form method="POST">
<input type="text" name="address">
<input type="submit" name="go" method="post">
</form>
With PHP once the form is submitted you can access form values with $_POST so use $_POST['address'] instead of document.address.value
what you intend to do can be done as below method.
<form method="post" >
<input type="text" name="address">
<input type="submit" name="go">
</form>
<?php
if($_POST){
if(isset($_POST['go'])){
call();
}else{
echo "Error";
}
}
function call(){
echo "hi";
echo $_POST['address'];
}
?>
Try like this,this is working fine as per your requirement:
<html>
<body>
<form action="" method="post">
Address: <input type="text" name="name"><br>
<input type="submit" name="go" value="call" />
</form>
<?php
if (isset($_REQUEST['name'])) {
call();
}
?>
<?php
function call() {
$address= $_POST['name'];
echo "Address:".$address;
exit;
}
Output:-
For output Click here
use this code
<input type="text" name="address">
<input type="submit" name="go" method="post">
<?php
if($_POST){
if(isset($_POST['go'])){
call();
}else{
echo "Error";
}
function call(){
echo "hi";
echo $_POST['address'];
}
?>
i'm still newbie in php, i want to connect this three page. I want to know how to tansfer data from signup to pfofile and also the sign in page. I tried to use tag but not working.
page=signup
<body>
<?php
// define variables and set to empty values
$email = $username = $name = $contact = $birthday = $gender = $address = $password = $payment ="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = test_input($_POST["email"]);
$username = test_input($_POST["username"]);
$name = test_input($_POST["name"]);
$contact = test_input($_POST["contact"]);
$birthday = test_input($_POST["birthday"]);
$gender = test_input($_POST["gender"]);
$address = test_input($_POST["address"]);
$password = test_input($_POST["password"]);
$payment = test_input($_POST["payment"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<div id="login">
<form id="registeration" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<fieldset>
<legend><h1>Registeration</h1></legend>
<p>Email:<br/>
<input type="email" name="email"></p>
<p>Username:<br/>
<input type="text" name="username" />
</p>
<p>Your Name:<br/>
<input type="text" name="name"/></p>
<p>Contact Number:<br/>
<input type="text" name="contact"/></p>
<p>Birthday:<br/>
<input type="date" name="birthday">
<p>Gender:<br/>
<input type="radio" name="gender" value="male"/>Male
<input type="radio" name="gender" value="female"/>Female
</p>
<p>Address: <br/>
<textarea name="address" cols="50"></textarea></p>
<p>Password:<br/>
<input name="password" type="password" size="50"/></p>
</p>
<h2>Choose payment method:<br/></h2>
<p><input type="radio" name="payment" value="cod"/>CASH ON DELIVERY</p>
<p><input type="radio" name="payment" value="Online Banking"/>ONLINE BANKING : CIMB Clicks<br/>
<p><input type="radio" name="payment" value="Online Banking"/>ONLINE BANKING : Maybank<br/>
<p><input type="radio" name="payment" value="Online Banking"/>ONLINE BANKING : BSN<br/>
<p><input type="radio" name="payment" value="atm"/>ATM</p>
<p><button type="submit" value="submit">Submit</button><span> <span><span><span><span>
<button type="reset" value="cancel">Cancel</button></p>
</fieldset>
</form>
</div>
echo $email;
echo "<br>";
echo $username;
echo "<br>";
echo $name;
echo "<br>";
echo $contact;
echo "<br>";
echo $birthday;
echo "<br>";
echo $gender;
echo "<br>";
echo $address;
echo "<br>";
echo $password;
echo "<br>";
echo $payment;
?>
</body>
page=signin
<body>
<div id="login">
<fieldset>
<legend><h1>Login</h1></legend>
<form id="signin" method="POST">
<p>Username:<br/>
<input type="text" name="username"/></p>
<p>Password:<br/>
<input type="password" name="password"/></p>
<p><button type="submit" value="submit">Submit</button><span>
<button type="reset" value="cancel">Cancel</button></p>
</form>
</fieldset>
<!-- end .content --></div>
<?php
error_reporting(0);
if (!empty ($_POST)){
if ($_POST ["username"] == NULL){
echo "Please insert your username!";}
else{
$strusername=$_POST["username"];
echo "<p>$strusername</p>";
}}
if (!empty ($_POST)){
if ($_POST ["password"] == NULL){
echo "Please insert the password!";}
else {
$strpassword=$_POST["password"];
echo "<p>$strpassword</p>";
}}
?>
</body>
page=profile
<body>
<div class="container">
<div class="content">
<table>
<td colspan="5"><b>PROFILE</b></td>
<tr>
<td><div align="left">Username:</div></td><td><?php echo $username ?></td></tr>
<td><div align="left">Name:</div></td><td><?php echo $name ?></td></tr>
<td><div align="left">Username:</div></td><td><?php echo $username ?></td></tr>
<td><div align="left">Birthday:</div></td><td><?php echo $birthday ?></td></tr>
<td><div align="left">Contact Number:</div></td><td><?php echo $contact ?></td></tr>
<td><div align="left">Gender:</div></td><td><?php echo $gender ?></td></tr>
<td><div align="left">Address:</div></td><td><?php echo $address ?></td></tr>
<td><div align="left">My payment Method:</div></td><td><?php echo $payment ?></td> </tr>
<tr>
<td><div align="left"><button type="submit" value="Edit Profile" >Edit Profile</button></div> </td>
</tr>
</table>
<!-- end .content --></div>
<!-- end .container --></div>
</body>
Well, Try to use the post and get.
The PHP superglobals $_GET and $_POST are used to collect form-data.The example below displays a simple HTML form with two input fields and a submit button:
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named "welcome.php". The form data is sent with the HTTP POST method.
To display the submitted data you could simply echo all the variables. The "welcome.php" looks like this:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
The output could be something like this:
Welcome John
Your email address is john.doe#example.com
The same result could also be achieved using the HTTP GET method:
<html>
<body>
<form action="welcome_get.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
and "welcome_get.php" looks like this:
<html>
<body>
Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>
</body>
</html>
I Suggest you to follow this tutorial here
I hope it will help you, best regards
Use $_SESSION
In every page start with <?php session_start(); ?>
then store $_SESSION['email'] = test_input($_POST["email"]);
Then in any page you can use echo $_SESSION['email'];
You should use SESSION for simple login functionality....
refer this tutorial about basic login and functionality