I am trying to see inputed texting using HTML and PHP.
From what I have written so far, I am trying to display a name and email after running through PHP, but the only thing shown is:
Welcome
Your email address is:
HTML:
<form action="index.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
PHP:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is:
<?php echo $_POST["email"]; ?>
</body>
</html>
How can I make it so I see the input submitted?
Related
I have 2 files, index.html, and welcome.php.
index.html:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
And here is the PHP:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
Echo seems to work whenever i'm not using $_POST, with just regular text or variables. Is there something I'm doing wrong? I am also writing this code on repl.it, could that have something to do with it? Major newbie here.
When I click on the submit button after filling name and mail id columns , data entered in those fields is not shown in php page.
HTML code :-
<html>
<body>
<form action="data.php" method="post">
Name: <input type="text" name="name" /><br>
E-mail: <input type="text" name="email"/><br>
<input type="submit">
</form>
</body>
</html>
PHP code :-
Welcome <?php echo $_REQUEST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
Try it like this;
HTML
<body>
<form action="data.php" method="post">
Name: <input type="text" name="name" /><br>
E-mail: <input type="text" name="email"/><br>
<input type="submit">
</form>
</body>
</html>
PHP
if ($_SERVER['REQUEST_METHOD'] === 'POST'){
if(isset($_POST["name"]) && isset($_POST["email"])){
$name = $_POST["name"];
$email = $_POST["email"];
if(!empty($name) && !empty($email){
echo "Your name is $name with the email : $email";
} else {
echo "Name or Email is not set";
}
}
}
I have a simple form where I want users to select items and those items appear on the results page. The items also include a link. I would like the link to be included on the results page too. Right now, I click on a check box with a link and the link does not appear on the results page. Not sure where to go from here.
<html>
<body>
Teaching Tools<br><br>
Testing version only<br><br>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
Building: <input type=“text” name=“bldg”><br><br><br>
Teaching Tools:<br><br>
<input type="checkbox" name="videos[]" value="Word"><label>Word</label><br /><br>
<input type="checkbox" name="videos[]" value="Padlet"> <label>Padlet</label><br />
<br>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
Results Page:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Email: <?php echo $_POST["email"]; ?><br><br>
Your building: <?php echo $_POST[“bldg”]; ?><br><br>
<?php
if(isset($_POST['submit'])) { // to run PHP script on submit
if(!empty($_POST['videos'])) {
// Loop to store and display values of individual checked checkbox.
foreach($_POST['videos'] as $selected) {
echo $selected."</br>";
}
}
}
?>
<br><br>Testing Mode<br>
</body>
</html>
Remove the link from the form and add this instead:
<input type="checkbox" name="link" value="http://www.bluevalleyk12.org">
On welcome.php get the value of link with :
$link = $_POST["link"];
If you want to hide the link use type="hidden":
<input type="hidden" name="link" value="http://www.bluevalleyk12.org">
Finally, if you want the link visible but non editable, use readonly:
<input type="checkbox" name="link" value="http://www.bluevalleyk12.org" readonly>
I get the following 404 error when trying to access a PHP file on MAMP
"The requested URL /‘welcome.php’ was not found on this server."
Both the html file and the php file run fine via localhost just not from the file action.
They are in the same location and the action looks like action='welcome.php'
<html><head charset=“utf-8”>></head><form action=‘welcome.php’ enctype="text/plain" method=“post”>
First name: <input type="text" name="firstname"><br> Last name: <input type="text"
name="lastname"> <button action=“submit”>Submit </button> </form> </html>
welcome.php looks like this
<html> <body> Welcome <?php echo $_POST["name"]; ?><br> Your email address is: <?php echo
$_POST["email"]; ?> </body> </html>
You have a few curly quotes in your code “ ” and ‘ ’ which will explain the "file not found" error for your form's action action=‘welcome.php’. You should also remove enctype="text/plain" - consult this answer on Stack for more information about it.
You are also using the wrong names name="firstname" and $_POST["name"].
Also name="lastname" and $_POST["email"], those must match.
Your Html file should now read as:
<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>
and welcome.php file:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
The requested URL /‘welcome.php’ was not found on this server.
This is because you use wrong quotes (quotation marks) in your HTML. In markup you should use nothing else then " or '.
So your code should looks like:
<html>
<head charset="utf-8"></head>
<body>
<form action="welcome.php" enctype="text/plain" method="post">
First name: <input type="text" name="firstname"><br>
Last name: <input type="text" name="lastname">
<button action="submit">Submit</button>
</form>
</body>
</html>
I have 2 html pages :
page1.html
<html>
<body>
<form action="page2.html" method="post">
Enter First name: <input type="text" id="text1">
<input type="submit" value="Next">
</form>
</body>
</html>
page2.html
<html>
<body>
<form action="test.php" method="post">
Enter Last name: <input type="text" id="text2">
<input type="submit" value="Submit">
</form>
</body>
</html>
Now, i would like to retrieve the value of text1 from page1.html and text2 from page2.html. How can i go about it?
Looks like you are looking for forms. See this tutorial http://www.w3schools.com/php/php_forms.asp. Post your form data from page1.php to page2.php. On page2.html you can access them via $_POST.
Please be aware: This is not a secure example, just for showing purposes! When you want to show user generated data in your frontend, please use sanitizing and validation http://www.php.net/manual/en/filter.examples.sanitization.php.
page1.php:
<form action="page2.php" method="post">
Enter first name: <input type="text" name="firstName"><br>
<input type="submit">
</form>
page2.php
<h1>Hey <?php echo $_POST['firstName']; ?></h1>
<form action="lastpage.php" method="post">
Enter last name: <input type="text" name="lastName"><br>
<input type="hidden" name="firstName" value="<?php echo $_POST['firstName']; ?>">
<input type="submit">
</form>
lastpage.php
<h1>Yo, my mate <?php echo $_POST['firstName']; ?> <?php echo $_POST['lastName']; ?>!</h1>