I have three pages One with HTML with the form (input variable) and its going to POST the variable to linkslvl2.php . With my third page i want to use the GET function and retrieve the variables from linkslvl2.php. When i click on the process i want it to automatically process linkslvl2 and print linkslvl3 statement. I'm stumped on how to pass it the variables along.
<!doctype html>
<html>
<head>
</head>
<body>
<h1 style="text-align:center;"> Super Hero</h1>
<form action="linklvltwo.php" method="post">
Please Enter a name:
Enter A super Hero Name:
Enter your weakness:
<!doctype html>
<html>
<head>
</head>
<body>
<?php
$name = $_POST['namep'];
$superHero = $_POST['superhero'];
$weakness = $_POST['weakness'];
?>
</body>
</html>
<!doctype html>
<html>
<head>
</head>
<body>
<?php
$person = $_GET['name'];
$chosenhero = $_GET['superHero'];
$chosenweakness = $_GET['weakness'];
print"
<p>$person you have chosen $chosenhero as you super hero, and your weakness $chosenweakness</p>
"
?>
</body>
</html>
perhaps you can try using $_REQUEST which gives you the parameters wether they are posted or "getted".
I think you can do this type of works in two way: 1) you can use db, file, session to save the value after submitting each form and use an id to indentify/get the previous values. 2) you can Submit the values of each steps via
Related
I want to echo the textarea value with PHP, so I create a simple form with HTML, and inside it I include textarea element with name of b64_place and then input to submit the values.
I check if b64_place is set, and if it is I echo the value of the textarea. But my program doesn't even get into the condition block, I try debugging and it is just not doing nothing.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<form action="index.php" method="GET">
<textarea name="b64_place" form="encode">Enter text here:</textarea>
<input type="submit" value="Encode">
</form>
<?php
if (isset($_GET['b64_place'])) {
$base64e_text = htmlspecialchars($_GET['b64_place']);
echo $base64e_text;
}
?>
</body>
</html>
Your textarea contains an attribute form This attribute is used to define the id of the form this input is attached to. So, when you submit the form, the textarea isn't bound with that form and the datas aren't send
You can either add an id to the form :
<!-- check this ----------------------v---------v -->
<form action="index.php" method="GET" id="encode">
<textarea name="b64_place" form="encode">Enter text here:</textarea>
<input type="submit" value="Encode">
</form>
or simply remove the form="encode"
Edit based on suggestion from senior SO members,
The reason i recommend you to change the method to POST is because of the length limit of the GET method. At some point you may want to encode very large data and it may get trimmed of because of URL length limit. But with POST you don't have to worry about this restriction.
Steps to solve your issue.
If your Form and your PHP code is in the same file changethe action="index.php" to action="" and change the method="GET" to method="POST"
In text area use placeholder to tell the user what to input instead of writing it between the tags.
change $_GET to $_POST everywhere in your code.
You can copy the following code into the index.php and it will work fine.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<form action="" method="POST">
<textarea name="b64_place" placeholder="Enter text here:"></textarea>
<input type="submit" value="Encode">
</form>
<?php
if (isset($_POST['b64_place'])) {
$base64e_text = htmlspecialchars($_POST['b64_place']);
echo $base64e_text;
}
?>
</body>
</html>
I have the following problem and feel that the solution is simple but after 8 hours of trying and searching, I am giving up.
I have this simple page:
<?php
// Start the session
$lifetime=600;
session_set_cookie_params($lifetime);
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Change the Yoda!</title>
</head>
<body>
<?php
// Set session variables
$_SESSION["post-data"] = $_POST;
?>
<form action="yoda_is.php" method="POST">
YODA IS: <input type="text" name="name">
<input type="submit">
</form>
</body>
</html>
Upon submit, it sends me to this page:
<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Who is Yoda?</title>
</head>
<body>
<?php
// Echo session variables that were set on previous page
echo "YODA IS " . $_SESSION['post-data'] = $_POST['name'];
?>!
</body>
</html>
The value that you enter in the first page, is successfully being displayed on the second page.
However, once I close the browser window and revisit the second page, the value is no longer there and it returns an error.
My question is simple, what am I doing wrong / do I need to do in order for the value that I entered on the first page, to be there after I revisit the second page?
Thank you so much for your help and suggestions, in advanced.
KR
MD
On your first page remove this:
// Set session variables
$_SESSION["post-data"] = $_POST;
On your second page use this instead:
// If the user filled out the form, set our session variable to the new value
if(isset($_POST['name']))
{
$_SESSION['post-data'] = $_POST['name'];
}
// Echo session variable set above
echo "YODA IS " . $_SESSION['post-data'] . "!";
I want a include a .php file to another one. But I want to do it many times. For each one I am going to pass concrete parameters. I want to print the result page on load.
for example imagin I have a html like this:
<html>
<body>
<div id="#friend1">
Name: <input/>
Age: <input />
</div>
<div id="#friend2">
Name: <input/>
Age: <input />
</div>
<button>print</button>
</body>
</html>
I have another file wich prints friends info in a cool wai like:
<html>
<body>
<div>
Yo are my friend<?php echo $_SESSION['friend']?> you are <?php echo $_SESSION['age']?>
</div>
</body>
</html>
I want to include this file with concrete info in order to print it. I have been trying with include o require with no succeed. Just one of them is shown. Parameters are passed correctly and I don-t know how to make it.
Any Ideas? Thank you, very much!
I'll try to be more specific:
<?php
session_start();
?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
<meta charset="utf-8">
<head>
</head>
<script type="text/javascript">
<?php
require_once ("jqdirectPrint.js");
?>
</script>
<body onload="printLoad();">
<?php
for ($i = 0; $i < sizeof($_SESSION['friendList']); $i++) {
$_SESSION['friend']=$_SESSION['friendList'][$i];
require 'friendInfo.php';
}
?>
</body>
</html>
friendInfor.php is just a html form which shows info for concrete friend. But just the first one is shown. I want to show same form for each elemnt on the list. It just contains tags.
Hobo Sapiens was right I had some extra tags on my friendInfo.php so I removed them and it worked fine. So thank you for your help. requireallows you to introduce or load same file many times.
Still waitting for some nice PHP manuals to check. ;)
I have used a form to send two variables from one page to another. Then I wanted the user to be able to click on a link (staying on the website) then once on the third page the variables to still be able to be used.
First page (which works fine):
<html>
<head>
<title> Form </title>
</head>
<body>
<form action="result.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
<br />
</body>
</html>
Then the second page (which displays the variables correctly):
<html>
<body>
Welcome <?php echo $_POST['name']; ?><br>
Your email address is: <?php echo $_POST['email']; ?>
link
</body>
</html>
Then when you click on the link from the second to the third (below) it doesn't work:
<html>
<head>
<title> Form </title>
</head>
<body>
<?php echo $_POST['name']; ?>
</body>
</html>
Thanks in advance for any help!
You have to put $_POST['name'] and $_POST['email'] in session variables.
One way to do that is:
link
On name.php you will have them as $_GET variables
if you just want to use these values on 3rd page only then better to use the above GET method. Otherwise you can put these values in session
Your second (result.php) page should look like this:
<?php
$_SESSION['name']= $_POST['name'];
$_SESSION['email']= $_POST['email'];
?>
<html>
<body>
Welcome <?php echo $_POST['name']; ?><br>
Your email address is: <?php echo $_POST['email']; ?>
link
</body>
</html>
And you third page (name.php) will work when you put it like this:
<html>
<head>
<title> Form </title>
</head>
<body>
<?php echo $_SESSION['name']; ?>
</body>
</html>
I have a simple form and I'm trying to pass the form variable to php and output the value. I have tried to solve this myself with the almighty google but wasn't successful. The html form code is as follows
<html>
<head>
<title>Form</title>
</head>
<body>
<form method="post" action="test1.php">
<input type="text" name="username">
<input type="submit">
</form>
</body>
</html>
Then the php to handle the form is:
<html>
<head>
<title>Form</title>
</head>
<body>
<?php
echo "<h1>Hello " . $_POST["username"] . "</h1>";
?>
</body>
</html>
The output I'm getting no matter what I type into the html form is , Hello " . $_POST["username"] . ""; ?>
I don't know why it also outputs the ending semi colon and ending php tag also, maybe this is evidence of what's going wrong here?
PHP is
misconfigured or
not configured or
not working or
not working within HTML files.
You have to configure your webserver that it parses PHP inside HTML files, see here for example:
=> Server not parsing .html as PHP
The syntax is fine, try to write a sample code snippet like below
<?
$a = "hello word!";
echo $a;
?>
and check if php is working.