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
Related
Which type of function can be used to collect form data sent both from GET and POST method
this is a question please tell me the ans thanks
Simple:
$_GET for getting GET data.
$_POST for getting POST data.
$_REQUEST- An associative array that by default contains the contents of $_GET, $_POST.
FirstPage.php
<form ..... action='submit.php' ... >
<input type='text' name='FirstName'>
</form>
submit.php
<?php
$name=$_REQUEST['FirstName'];
echo $name;
?>
Check this $_REQUEST - PHP Manual and $_REQUEST - W3-Resource
I have my index.php page that sends values over to edit.php via $_GET/html link. I can see the values go, including the table ID I want to use using echo statements. The problem is that I need the specific ID value used in another form using a submit form($_POST). I've tried different approaches including SESSION, making the $ID = $_GET.... I'm pulling my hair out.
Here is the order of things:
//Edit link on index.php sends the id='summary_id', which works
<td align="center">Edit</td>
//Edit.php grabs the variable and I set it to that variable
if(isset($_GET['id']))
echo "<pre>Value of GET \$_GET:</br>";print_r($_GET);echo"</pre>";
{
$summary_id = $_GET['id'];
$summary_id = $_POST['summary_id'];
But, when I try to use $summary_id in a form (using $_POST this time), I get no value. I'm not sure if what I'm trying to do is "legal". I've tried sending the summary_id as a hidden value in the form, but again, nothing is going through. I'm losing it after that initial $_GET.
You are doing wrong.You are overwriting the variable that is not available $_POST['summary_id']
if you really want to use post method use this
<form action="edit.php" method="POST">
<input type="hidden" value="<?php echo $row['summary_id'];?>" name="summary_id"/>
<input type="submit" value="EDIT"/>
</form>
or you can use header() to post the value
You are overwriting your own variable. Also, it's clear from this that you don't actually have PHP errors turned on.
You could use $_REQUEST instead as it contains both $_GET and $_POST.
I use one view for adding/editing DB data:
<input name="blah" id="blah" value="<? set_selected('blah')?> />
In my controller for edit I do this:
$_POST['blah'] = 'DB value';
$this->load->view('...');
But the input field is blank. I want the inputs to be prepopulated for my edit case.
CI Views can take a data array as the second parameter as others have mentioned.
http://codeigniter.com/user_guide/general/views.html
I don't like the idea of setting the $_POST array and then passing that as your data array. $_POST should just be used for values passed from the UI form. Since you would have to manually set your $_POST array anyways, you might as well use a separate array object. I would create an array with all your set values. i.e. array('blah' => $dbvalue); and pass that instead of a pre-populated $_POST array.
Secondly, your example code uses 'set_selected()'. The function is 'set_select()' and is meant for a option tag. So there are two issues with that line of code. It needs to either be
<input .... value="set_value('blah')" />
or
<option ....value="v1" "set_select('blah', 'v1')">
You need to pass $_POST to view, the posted data should pass from the controller to the view in the second parameter of the view loading function.
try this
$this->load->view('content', $_POST);
Whatever you pass to the view get turned into an actual variable. So your code would be.
<input name="blah" id="blah" value="<?php echo $blah; ?> />
$_POST['blah'] = 'DB value';
$this->load->view('...', $_POST);
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']