I have a html-form which looks like this:
<form action="lib/AdminPage.php" method="post" id="adminLogin">
Admin-Login: <input type="password" name="pw" value="" class="pw">
<input type="submit" value="Login">
AdminPage.php contains the following lines:
<?php
echo($_GET['pw']);
echo($_GET['adminLogin']);
echo($_GET['Login']);
echo($_GET['id']);
echo($_GET['value']);
echo($_GET['name']);
echo($pw);
echo($_GET["pw"]);
echo($_GET["adminLogin"]);
echo($_GET["Login"]);
echo($_GET["id"]);
echo($_GET["value"]);
echo($_GET["name"]);
?>
None of the echoes works, it's always an "Undefined index" or "Undefined variable" with echo($pw)
How can I retrieve the entered string from the from?
Regards
Use $_POST instead of $_GET, because you have method="post" in your form.
You are sending the form using POST but looking for GET variables. Replace $_GET with $_POST.
Since you have method="post" in your form <form action="lib/AdminPage.php" method="post" id="adminLogin">, variables are accessed as _POST variables. So, you should do
echo $_POST['pw'];
All you need to do is this:
echo $_POST['pw'];
Your HTML form has method="post" in it so you get all information from inputs via $_POST instead of $_GET.
use the $_POST array, not $_GET
Your form uses the POST HTTP method, hence this should work.
echo($_POST['pw']);
echo($_POST['adminLogin']);
echo($_POST['Login']);
echo($_POST['id']);
echo($_POST['value']);
echo($_POST['name']);
You need to post the values. But, you are trying to get those through $_GET.
Try changing everywhere $_GET by $_POST
Change like this :
echo($_POST['pw']);
echo($_POST['adminLogin']);
echo($_POST['Login']);
echo($_POST['id']);
echo($_POST['value']);
echo($_POST['name']);
Related
I want to POST values coming from a url .
My url is xxx.com/aa.php?name=RAM
On aa.php page I have written like this
<?php $NAME=$_POST["name"]; ?>
but its value is getting null .
but when using GET Method its values is getting as 'RAM'.
How can I retrieve values using POST from a url ? or is it not possible?
Use $_GET instead of $_POST
<?php $NAME=$_GET["name"]; ?>
If you are not sure about $_GET & $_POST method then you can try $_REQUEST also.
$NAME=$_GET["name"]; //work in get method
$NAME=$_POST["name"]; //work in post method
$NAME=$_REQUEST["name"]; //work in both method
When the parameter is in the URL it is a GET parameter.
You can not fetch a GET parameter from the $_POST array, but the $_GET array.
You can also use the $_REQUEST Array to get both POST and GET variables.
In your case, the GET variable with the key name is RAM, as it should be.
edit:
Worth to mention is that the $_REQUEST array pretty much is a concatenation of $_POST, $_GET and $_COOKIE, so it might behave unexpected if any of the others (than the one you are after) are using the same key names.
I would recommend using the type you are actually wanting, in this case, the $_GET list.
The only solution to pass the data with hidden method is either you should use curl or using form submission with post method like
<form name="" action="aa.php" method="post">
<input typ="hidden" name="name" value="RAM">
<input type="submit" name="submit" value="submit">
</form>
then you can get this as
$_POST['name']
on aa.php page
if you are not sure about your method i.e. $_GET or $_POST.you should use $_REQUEST.
$NAME=$_REQUEST["name"];
for more information:http://www.tutorialspoint.com/php/php_get_post.htm
This is probably a really easy question but its early so yeah...
Basically I have a form:
<form name="varsForm" action="step2.php" id="formID" method="post">
And as I understand it within this for I created some hidden variables. as follows:
<input type="hidden" id="typeid" name="typeid" value="1" />
Because step2.php is set as an action, I though I was correct in assuming that the hidden variables would be passed to step2.php. However when I try to call them I am confronted with errors. I try and call them simply as follows:
<?php echo $_GET['typeid']; ?>
But it says that caseid is an undefined index, I assume I am not calling it correctly, anyone just put me right please?
You are submitting form via POST method, try $_POST['typeid'];
Alternatively change method to GET.
Since you are using method="post" in form, you should use
<?php echo $_POST['typeid']; ?>
$_GET in PHP is used when you use HTTP GET method (method="get" in form tag).
You're using the $_GET array while you're posting your infos.
You should use the $_POST array, or even the $_REQUEST array which handles both POST and GET.
You have method="post" so the data is placed in the message body and not the query string. It will be accessible via $_POST not $_GET.
You are using method="post" so look in $_POST :)
<?php echo $_POST['typeid']; ?>
HTH
Since you are using HTTP POST method in your <form> you need to give the code as:
<?php echo $_POST['typeid']; ?>
Else, in the HTML change this:
<form method="get">
You have method attribute in the form set to POST so values passed to step2.php will not be available in $_GET , it will be available in $_POST so to access the value you need to use $_POST['typeid'] .
And also Some times to avoid warnings OR notifications regarding index ( such as undefined index ) , you can first check for its existence and then process
Some what like this
if (array_key_exists('typeid', $_POST) )
{
$typeid = $_POST['type_id'];
// And do what ever you want to do with this value
}
I have a simple php test page as follows
<?php
if(isset($_POST['hitme']))
{
echo "hello world";
}
?>
I'm hitting this page as, http://www.abc.com/page.php?hitme=true but this is not echo'ing anything. Is something wrong with this?
Use $_GET['hitme'], not $_POST, since you passed the value in the query string. $_POST would hold values sent via a <form action='post'>, but not values passed in the query string.
if(isset($_GET['hitme'])) {...}
It's recommended to read about the differences between PHP's superglobal arrays.
$_POST only contains variables which are posted to the page as part of an HTTP POST request. If you are typing the address into your browsers address bar, you're issuing a GET request, not a POST request, and no variables will be set in $_POST. Even if you are issuing a POST request, variables specified on the query string will still only be available inside $_GET, so for this example your using the wrong array either way.
You must use $_GET instead of $_POST when it's in the URL
If it's in the URL, e.g. http://example.com/index.php?hitme=true, it's in $_GET.
However, if you want it to be in $_POST, you'd have to do something like this (very basic example):
<form method="post" action="page.php">
<input type="checkbox" name="hitme" value="true" />
<input type="submit" value="Post data!" />
</form>
This script will allow the user to check it if wanted, and then click "Post data!".
However, it won't be in $_POST as long the user didn't click the button.
As for $_GET, it will be there as long as it's in the URL.
Or you can use $_REQUEST['hitme'], this one will check both $_POST['hitme'] and $_GET['hitme']
I am reading a script but am stuck on understanding this:
$redirect = base64_decode($_REQUEST['redirect']);
header("Location:$redirect");exit;
because the redirect variable in REQUEST isn't defined anywhere in the script. Prior to this a POST form has been filled in, but there is NO mention of the redirect variable anywhere in the script so I am confused how it is not empty...
EDIT:
here's the form code below. btw like I said, the word 'redirect' doesn't appear ANYWHERE in the script, which is what is confusing me.
<form name="login" action="{$baseurl}/login" method="post">
{$lang12}
<input type="text" name="username" />
{$lang11}
<input type="password" name="password" />
<input type="submit" value="{$lang18}" />
<div class="test"><b>{$lang30}</b> - {$lang19}</div>
<input type="hidden" name="authenticate" value="1" />
</form>
</div>
The $lang stuff is commonly appearing words from an array, e.g login, etc.
I don't think this is possible to answer for certain without seeing the actual code but $_REQUEST holds all the variables in $_GET, $_POST and $_COOKIE.
A form can actually populate both $_GET and $_POST if its method is set to 'post' and its action is a url with url encoded variables. Thus the form might be posting all of its data to a url and then adding get variables to the end of that url. For example:
<form method='post' action='example.php?var=test'>
<input name='var2' id='var2' />
</form>
If that form were submitted, the following would be defined: $_POST['var2'], $_GET['var'], $_REQUEST['var2'], $_REQUEST['var'].
$_COOKIE could also be putting hidden variables in $_REQUEST.
$_REQUEST
An associative array that by default
contains the contents of $_GET, $_POST
and $_COOKIE.
So if you have $_POST['redirect'], $_GET['redirect'] or $_COOKIE['redirect'], $_REQUEST['redirect'] will be defined. Try to put:
var_dump($_POST['redirect']);
var_dump($_GET['redirect']);
var_dump($_COOKIE['redirect']);
To find out where it's coming from.
it have so much possibility that the redirect variable is a cookies. if you cannot find it at the form.
var_dump($_REGISTER);
that will list all your input variable associated with POST, GET and COOKIES.
If it's not empty what's the content of it?
I think it should be something like this...
$redirect = base64_decode($_GET['redirect']);
if(!empty($redirect){
header("Location: $redirect");
exit;
}
It doesn't matter that it's not in the script, you can set it via GET,
eg /yourform.php?redirect=index.php
Is it causing unwanted redirection?
I have a form and the method is set to post on the action page when I use $_POST i dont get the value but if I use $_GET or $_REQUEST I do.
This does not make sense. Could someone just clarify it for me?
The code of the form is
<form action="create.php" method"POST">
Just realized I am missing the = after method.
It sounds like you've misplaced or mistyped the method attribute and your form is defaulting to HTTP GET. The form should look like this:
<form method="post" action="file.html">
What's the method set to in the HTML for your form, eg:
<form method="POST" ...>
In PHP ini file, the default setting GPC (Get, Post, Cookie) and Request array has that in itself. And make sure that you really the the POST in the action attribute.
It looks like you typoed your HTML:
<form action="create.php" method"POST">
should be
<form action="create.php" method="POST">
You're missing an equal sign.
<form action="create.php" method="POST">
your missing equal sign after the method
POST and GET are different methods to transfer form data, they both use different ways to send the entered values to your application and have to be handled differently. PHP uses $_POST for the values submitted by a form with method="post" and $_GET for values submitted by a form without a method or with method="get". $_REQUEST is a combination of $_POST and $_GET.
The easiest to see difference is:
Parameters submitted with GET appear in the adress bar, i.e.
http://example.com/index.php?page=home
passes the key page with the value home to $_GET.
Post parameters do not appear in the adress bar.
Your method attribute is wrong, should be:
<form action="create.php" method="POST">
Hehe :-)
<form action="create.php" method="POST">
Your sloppy way of writing is not good for coding...
The error seems to be the missing "=" :)
BTW, the $_REQUEST variable isn't just a combination of $_POST and $_GET, it's an associative array that by default contains the contents of $_GET, $_POST and $_COOKIE. ;)