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. ;)
Related
If we have 2 html files (i.e. one.html and two.html) and within both we have a form which calls the same php file on submit, like:
<form method="post" action="example.php">
, how can example.php know which html file called it?
I'm new to php so any comments are appreciated.
See http://php.net/manual/en/reserved.variables.server.php
The $_SERVER['HTTP_REFERER'] variable, while not trustworthy from a security standpoint, will provide you what you want in most cases.
You could also put a hidden input in your form and pass a variable with the form name or some id that you could use.
There are some ways to solve this problem. It is possible to read the referer from $_SERVER['HTTP_REFERER'].
Or you set a parameter in your form to identify from where you come.
<form method="post" action="example.php?id=xy">
in your example.php you can read the $_GET['id'] and do something with a if statement or a switch.
I have a form in my site. I wanna add GET and post option together. Which will indicate 2 different destination.
Example : -
when someone submit a form ( name and address ) then he can enter a restricted section.
Then code will be
<form name="loginform"
action="http://site.com/viparea"
method="post">
And beside this i wanna keep a log.And for the log code is
<form name="loginform"
action="logcode.php"
method="GET">
And encrypted log will be save in a text file.
I have used two methods individually . And those are working fine individually.
But i wanna make them work together.
So, i am not a coder but after searching something i just did a simple work like a noob :P .
<form name="loginform"
action="http://site.com/viparea"
method="post"><form name="loginform"
action="logcode.php"
method="GET">
But not working. Any suggestion please.
You can only achieve this by using:
<form name="loginform" action="http://site.com/viparea?var1=var&var2=var" method="post">
<input type="text" name="var3" />
</form>
this way you will get var1 and var2 as $_GET, var3 as $_POST OR all 3 vars as $_REQUEST
No, you can't; but in php you can use $_REQUEST[], to see data from both GET and POST; you may need just a little changes in your php code.
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 would like to use the data entered in the html form and insert into MYSQL. I have a separate php (cus.php). but nothing is happening with current code I have
at the moment when I click "register" I'm nav to the php file. Thank you
You forgot the most important thing about an HTML form: the <form> tag.
You have to wrap the whole form (all inputs) which should be submitted when clicking like this:
<form method="POST" action="cus.php">
...
</form>
This will send all inputs to cus.php and make them available there as variables $_POST['input_name']. You can alternatively use GET as the method (and then use the $_GET array instead).
Edit: Didn't see it, you actually do have a form tag. However it's missing the target file in its action attribute.
First, see DCoder's comment. It's the most important.
Change:
<form action="" method="seller">
To:
<form action="cus.php" method="post">
Does that fix it?
Try to do this
FORM action="your script" method="Post"
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']);