PHP form not sending data to $_POST - php

<!DOCTYPE html>
<html>
<body>
<form action="test.php" method="post">
<input name="test" type="text">
<input type="password" name="data">
<input type="submit">
</form>
</body>
</html>
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$name = $_POST['test'];
$pass = $_POST['data'];
}
?>
I am trying to make a simple form in PHP that users will use for login. When using this code, nothing ever gets put inside the $_POST. I am debugging using PHPstorm and I can tell that the request method is definitely POST, but no data is getting passed through. What am I doing wrong?

Try adding a slash at the begening of the action parameter of the form tag.
<form action="/test.php" method="post">

Try to remove "action" from form. It worked for me.
Code: http://nimb.ws/6pXjnz
Output:http://nimb.ws/PvuxZs

Related

How to show value of input in PHP?

I have this input field in a form:
<form method="post" class="tester" enctype="multipart/form-data" action="#">
<input type="number" name="test">
</form>
Whenever I try to get the input / value of the input data, filled in by my users, I can not show it (it just does not echo it). This is the code I use to echo it:
<?php
$well = $_POST['test'];
echo $well;
?>
I tried using GET as well, but nothing works.
var_dump gives me:
array(0) { }
Can you help?
Your form do not seem to have any issue even after using hash# it still process the form. Also your PHP code it's fine.
index.php
<form method="post" class="tester" enctype="multipart/form-data" action="#">
<input type="number" name="test">
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$well = $_POST['test'];
echo $well;
//print_r($_POST);
}

Get variable from Post Data (PHP)

I really don't know why my code isn't working! Let me clear it by example..
I got a file named 'index.html' example...
<html>
<body>
<form action="test.php" method="post">
Name: <input type="text" name="test">
<input type="submit">
</form>
</body>
</html>
And of course the form action file test.php .. example..
<?php
$something = ($_POST["test"]);
// from here I have some PHP codes and this "something" variable will be process in this codes and will print out something spacial..
?>
Now example If I post "Hello, It's not working" then the output will show a spacial design.
But Instead process, it's just printing out whatever I submit in that form.
But when I manually add the variable to "something" and if I execute the "test.php" . Example..
$something = "Hello, It's not working";
Then it works perfectly..
And yes. Also tried GET method.. It's still same as POST.
This is my first question here..
Thanks for any help and suggestions!
First Convert, index.html to php and follow this code:-
<html>
<body>
<form action="test.php" method="post">
Name: <input type="text" value="" name="test">
<input name="submit" value="submit" type="submit">
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])){
$something = $_POST["test"];
}
?>
That's correct _POST:
<?php
//NO ($_POST["test"])
$something = $_POST["test"];
?>

How to acess form details in php page using html 'id' attribute

i have a form having employeeNo,name and a submit button. when the form is submitted it redirects to a php page, Now the problem is i want to access the values of the form by using 'id' attribute?if possible i need the html and php code.
Is there a way to solve this Problem?
enter code here<html>
<head>
</head>
<body>
<form action="test.php" method="">
<input type="text" name='employeeNo' id="input1">
<br>
<input type="text" name='name' id="input2">
<br>
<input type="submit" id="input3">
</form>
</body></html>
In your test.php file you need to retrieve the values. Since you don't define any method in your form, by default it should be "GET"
Your php file could look like the following:
<?php
$employee_no = $_GET['employeeNo'];
$name = $_GET['name'];
I would suggest defining your form method as POST though, like the following:
...
<form action="test.php" method="POST">
...
so your php file will retrieve values from form like this:
<?php
$employee_no = $_POST['employeeNo'];
$name = $_POST['name'];
You may also look at this for further explanation:
https://www.w3schools.com/php/php_forms.asp

$_POST coming in empty after submit

I'm writing a webpage, and am trying to use php to check a value after a form submits. The php is in the same page, as seen below. The $_POST variable is coming in empty after the submit code comes in though. I've looked at the other posts about this question but none of those answers seem to help.
Thanks for looking
<?php
session_start();
require_once 'assets/PHP/membership.php';
$membership = new Membership();
var_dump($_SESSION);
var_dump($_POST);
if($_POST && !empty($_POST['username']) && !empty($_POST['pwd']))
{
$response = $membership->validate_user($_POST['username'], $_POST['pwd']);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<div id="login">
<form method="post" action = "">
<h2>LOG IN:</h2>
<label>User Name :</label>
<input type="text" name="username" id = "username"/>
<label>Password :</label>
<input type="password" name="pwd" id = "pwd"/>
<input type="submit" value="Login" id="submit" name="submit"/>
</form>
</div>
</html>
I'm very new to HTML and PHP so any help I could get would go a long way.
For anyone who is curious, I solved this by finding this reddit link: https://www.reddit.com/r/PHPhelp/comments/3uxapu/phpstorm_local_php_5616_post_always_empty/
All my superglobals were coming in blank. I'm not even sure why quite yet, I still need to read more about it. The following code snippet got me the results I needed:
$post_data = file_get_contents('php://input');
Post data now contains what I wanted to get from $_POST.
Thanks to everyone who tried to help me here!
If you want print $_post thn use code this....
If(isset($_POST['submit'])){
Print_r($_POST);
}
It's because, if you want to print data from form then you must submit the form first then you'll be able to get data in $_post.....

Concatenating strings retrieved from form $_Post in php

I am posting a string through an HTML form with the following code:
<html>
<body>
<form name="form" enctype="multipart/form-data" action="test.php" method="post">
<input name="message"
type="text" value=""><br/><br/>
<input type="submit" value="Upload"/><br/>
</form>
</body>
</html>
The code for test.php is the following:
<?php
$string1 = '$_POST["message"]';
$og_url = "http://thepropagator.com/facebook/testapp/issue.php?name=".$string1;
echo $og_url;
?>
The problem I'm having is that the posted string "$string1" does not seem to be showing at the end of the URL "http://thepropagator.com/facebook/testapp/issue.php?name=" that I am trying to concatenate it with. Can anyone please explain what I'm doing wrong?
I think you want $string1 = $_POST['message'];, no quotes. Though I'd expect your code to come up with http://thepropagator.com/facebook/testapp/issue.php?name=$_POST["message"] url.

Categories