Get variable from Post Data (PHP) - 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"];
?>

Related

Creating a single file small PHP piece

Can anyone help me make this work? I am very very new to PHP and I was just trying to create a single file thing which asks for a name and returns it. Can anyone help see where I am going wrong? I am testing it on wtools.io
Thanks in advance for any help :)
<form method="POST" action="formFunction()" name="form1">
Name: <input type="text" name="name">
<input name="s1" value="Submit LoL !" type="submit">
</form>
<?php
function formFunction() {
$name = $_POST['name'];
echo $name;
}```
You cannot call a PHP function as the action of your form. Instead, you should create a second file/script, something like post.php, and use that as the action. For example:
<form action="post.php" method="post" name="form1">
Then, in your post.php:
<?php
if (!$_POST) {
print "This should only be called on form submit.";
exit();
}
// you should actually test to see if name is supplied before this next line
$name = $_POST['name'];
echo $name;
?>
<!-- do some other stuff... -->
A similar question for your review Calling a particular PHP function on form submit

PHP form not sending data to $_POST

<!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

How to pass a variable from one file to another in PHP through a button and without and input

I have a search functionality that it works as shown below, but I would like to be able to pass a variable from a php file to another file without having an input like I have in my search function.
This is search functionality that works:
I have the following index.html file
<html>
<body>
<p>Search</p>
<form name"form1" method="post" action="searchresults.php">
<input name="search" type="text" size="40" maxlength="50">
<input type="submit" name="submit" value="Search">
</form>
</body>
</html>
and I have my searchresults.php file
<?php
$nameofcity = $_POST['search'];
?>
Something like this is what I would like to have but not sure how to do it.
index.php file
<html>
<body>
<p>Search</p>
<?php
$variabletopass = "London";
echo '<form name"form1" method="post" action="searchresults.php">';
echo '<input type="submit" name="submit" value="Search">';
</form>
?>
</body>
</html>
my searchresults.php file where I want the $nameofcity to be equal to the value of $variabletopass, in the example = London.
<?php
$nameofcity = $_POST['search'];
?>
You could try session. For example,
// index.php
$_SESSION['variabletopass'] = "London";
//searchresults.php
echo $_SESSION['variabletopass']; // Prints London
Hope this helps.

Cannot submit HTML form using PHP on iPad

Recently I got this problem that I cannot solve. My HTML form cannot be submitted by using iPad, but the same form CAN be submitted from my laptop (windows machine). Please check this out:
http://www.gomap.ch/admin/pages/test.php - this is submitted correctly
http://ipadpreview.com/previewer?url=www.gomap.ch/admin/pages/test.php - this is not submitted.
This is a very simple form, and code goes like this:
<?php
error_reporting(0);
if($_POST['mirko']){
echo 'hello, Mirko';
}
?>
<form action="" method="POST">
<input type="submit" value="Submit" name="mirko"/>
</form>
Any help, please??
Thanks a lot!
You are not using valid html.Replace your code with this and have u tried on real ipad.
<html>
<head></head>
<body>
<?php
error_reporting(0);
if($_POST['mirko']){
echo 'hello, Mirko';
}
?>
<form action="" method="POST">
<input type="submit" value="Submit" name="mirko"/>
</form>
</body>
</html>
You need to add the name of the form which holds the php code into the action. In this case it would be the same form you're on. Follow what I did below with nameOfFile.php being the name of the file you posted.
<?php
error_reporting(0);
if($_POST['mirko']){
echo 'hello, Mirko';
}
?>
<form action="nameOfFile.php" method="POST">
<input type="submit" value="Submit" name="mirko"/>
</form>

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