I'm having problems passing data from a form, I can't figure out where I've gone wrong. I have modeled my page on one that works but mine does not function.
I want to check I have the general structure right. I have stripped it right down and it still wont work.
<?php
define('INCLUDE_CHECK',true);
include 'php/functions.php';
error_reporting(E_ALL);
ini_set('display_errors',1);
logThis('ready!');
if (isset($_POST['submit'])) {
logThis('success');
}
?>
<html>
<head>
</head>
<body>
<form method="post" action="">
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
</body>
</html>
This is the whole page now, I have commented everything else out.
logThis() works i get the 'ready!' in the log but no 'success' message when ever i press the submit button.
Sorry for my bad english!
In PHP, $_POST expect the name of input field, not the id.
So you need to set names to your fields:
<input type="hidden" id="villainClass" name="villainClass" value="" />
<input type="hidden" id="heroClass" name="heroClass" value="" />
Modify your HTML code
You can get posted data only by the name of input field
<?php
if(isset($_POST["username"]))
{
$username = $_POST["username"];
echo $username;
}
?>
<html>
<head>
</head>
<body>
<form method="post" action="">
<input type="text" name="username"/>
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
</body>
</html>
Related
So the goal is to take the input from a form append it to the end of the URL and then return the HTML from that page.
I am not entirely sure how to take the forms value (in this case $2) and attach it to the URL.
<html>
<head>
<title>Metar Test</title>
</head>
<body>
<form action="" method="POST">
<p>IACO Code: <input type="text" name="$2" value=""></p>
<input type="submit" name="submit" value="Submit">
</form>
<?php $html=file_get_contents("http://www.metar.mysite.net/metar?id=$2")?>
<?php echo $_POST ["$html"];?>
</body>
</html>
On submit any input from a form with method="POST" will be stored in the $_POST global. You can access it from there and append it to your URL string.
<html>
<head>
<title>Metar Test</title>
</head>
<body>
<form action="" method="POST">
<p>IACO Code: <input type="text" name="iacoCode" value=""></p>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if (isset($_POST["iacoCode"])) {
$html = file_get_contents("http://www.metar.mysite.net/metar?id=" . $_POST["iacoCode"]);
echo $html;
}
?>
</body>
</html>
Using the IF statement to check if it is set will prevent it from loading the URL with no variable.
The way we extract data via php from a form is like below
<html>
<head>
<title>Metar Test</title>
</head>
<body>
<form action="" method="POST">
<p>IACO Code: <input type="text" name="$2" value=""></p>
<input type="submit" name="submit" value="Submit">
</form>
<?php $html=file_get_contents("http://www.metar.mysite.net/metar?id=$_POST['$2']")?>
<?php echo $_POST ["$html"];?>
I just start learning php and html and I wanted to make something that gets input and print out the output with php code. However, with the code I have, it lets me input, but not printing anything when I click submit. Why?
<html>
<head><title>Noob</title></head>
<body>
<form action="" method="post">
<input type="text" name="username" value="" />
<input type="submit" name="submit value="Submit" />
</form>
<?php
if (isset($_POST['submit'])) { //to check if the form was submitted
$username= $_POST['username'];
echo $username;
}
?>
</body>
<html>
In the below line in your code
<input type="submit" name="submit value="Submit" />
the word name = "submit does not have a closing double colon
Your HTML is missing a quotation mark on the line where you have
<input type="submit" name="submit value="Submit" />
it should be
<input type="submit" name="submit" value="Submit" />
you missed the quotes in button name
<html>
<head><title>Noob</title></head>
<body>
<form action="" method="post">
<input type="text" name="username" value="" />
<input type="submit" name="submit" value="Submit" />// you missed here
</form>
<?php
if (isset($_POST['submit'])) { //to check if the form was submitted
$username= $_POST['username'];
echo $username;
}
?>
</body>
<html>
There is a syntax error you have missed the double quotes name="submit"
<?php
if (isset($_POST['submit'])) { //to check if the form was submitted
// For printing whole post data
echo '<pre>'; print_r($_POST);
$username= $_POST['username'];
echo $username;
}
?>
You can also use var_dump for printing out.
Hope this will help you.
are you sure you run the page via php interpreter?
in local you can use xampp or wampp(product by windows)
in mac you can use mampp
index.php
<html>
<head>
<script type="text/javascript">
function submitForms()
{
document.forms["form-1"].submit();
document.forms["form-2"].submit();
}
</script>
</head>
<body>
<form method="POST" action="form.php" id='form-1'>
<input type="text" name="txt1" />
</form>
<form method="POST" action="form.php" id='form-2'>
<input type="text" name="txt2" />
</form>
<input type="button" value="Click Me!" onclick="submitForms();" />
</body>
</html>
form.php
<?php
echo $_POST['txt1'];
echo $_POST['txt2'];
?>
Above is my code and when i submit both forms then both text-fields with their value it does not shoe me both text-field values.It only shoe me second text-field value.Please help me quickly.
I think because you try to get the params after sumbit two forms. You have sent the two forms at once and the second has stepped to the first, so the result is the return of the second form.
I think this will be better:
<html>
<head>
</head>
<body>
<form method="POST" action="form.php">
<input type="text" name="txt1" />
<input type="text" name="txt2" />
<input type="submit" value="Click Me!" />
</form>
</body>
</html>
<?php
echo $_POST['txt1'];
echo $_POST['txt2'];
?>
Sorry for my english
I do apologise in advance for my lack of knowledge in PHP and HTML. I have scoured the internet for 3/4 days trying to create what is probably a simple system. I need the user to enter a digit before the next page is loaded. I have an IF statement on my page.
1.php
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/reset.css" rel="stylesheet" type="text/css" />
<div id="container">
<div id="authorise">
<form action="2.php" method="post">
<!--Product Comment Box--><br>
<p>Please enter your 4<br> digit authorisation code:<br> <br>
<input type="text" name="digits" />
<input type="submit" name="submit" />
</form>
</div>
</div>
2.php
<?php
if ($_POST['digits'] === '210392')
{echo 'https://www.facebook.com/'
?>
But I need a form first which the user would input the code '210392' and press submit. Then the if statement can take place. I know how to do a form but dont know how to assign that form a variable name 'digits'. All help is appreciated.
A basic form:
<form action="your_file.php" method="post">
<input type="text" name="digits" />
<input type="submit" name="submit" />
</form>
Then in your_file.php:
<?php
if ($_POST['digits'] === '210392') {
// etc.
$_POST is a superglobal array that has all data POSTed to your script. digits in this case is an index in that array. It comes from the name of the input field.
<form action="check.php" method="POST">
<input type="text" name="digits" />
<input type="submit" value="click here" />
</form>
//in check.php
if (isset($_POST['digits']) and $_POST['digits'] == 12345){
header("Location: http://google.com");
}
else {
echo " error !!";
}
study html from w3school
http://www.w3schools.com/html/html_forms.asp
and php
http://www.w3schools.com/PhP/php_forms.asp
<form action="https://scm-intranet.tees.ac.uk/users/l1071039/bobbin/admin.php" method="post">
Password : <input type="password" name="pwd" />
<input type="submit" name="send">
</form>
// admin.php
<?php
if( isset($_POST['pwd']) ){
$pwd = $_POST['pwd'];
}
?>
You first need to create an input with the very important name attribute which you'll use later.
<form method="post">
<input type="password" name="mypassword" />
<button type="submit">Go</button>
</form>
PHP:
//Post method access with $_POST variable:
if ($_POST['mypassword'] == 'my-password') { //Oh, you should probably use SSH and hash the password
//Hooray!
}
Instead of echo, use header.
<?php
if ($_POST['digits'] === '210392')
{
header (loaction:https://www.facebook.com/);
}
?>
I am new to PHP (in-fact I am learning it). I am trying to get the value of textbox defined in HTML and print it on HTML page through PHP code. I am able to send the value of textbox to another page using form post and getting it using $_POST['name'] on other page.
I am not able to print the value of textbox on same page.
Here is my code:
<html>
<head>
<?php
function myfunction()
{
printf($_POST['fname']);
}
?>
</head>
<body>
Name: <input type="text" name="fname" />
<input type="button" onClick="myfunction()" value="Click" />
</body>
</html>
First of all it's not required to write php function within <head> tags. Second,
you can't POST data without <form> tags. try this
<?php
if(isset($_POST['submit']) && $_POST['submit']=='Submit'){
$name=$_POST['fname'];
echo $name;
}
else {
?>
<html>
<head>
</head>
<body>
<form method="POST" action="<?=$_SERVER["PHP_SELF"]?>">
Name: <input type="text" name="fname" />
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
<?php } ?>
you can not call PHP function by button's click event...
if you want to print on same page then you can do by below code..
<html>
<?php
if(count($_POST)>0){
echo $_POST['fname'];
}
?>
<body>
<form method='post'>
Name: <input type="text" name="fname" />
<input type="submit" value="Click" />
</form>
</body>
</html>
hope you will get what you want by my answer..