Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to receive values of variables using $_GET and $_POST in the same 2

Status
Not open for further replies.

amir4oracle

Programmer
Nov 3, 2004
46
CA
I need your help, in regards to how to receive values of different variables using $_GET and $_POST in the same form.

I am actually working on a website, in which there is a small form.

The form is getting a value "order_number" from another web page "A" using $_GET method.

The same form has a field "addi_info" in html part which is being sent to the php part of the form using $_POST method.

The web page "A" is sending the order_number cleanly without a problem.

When the submit button is clicked it gives the following error:
Notice: Undefined index: order_number in D:\ on line 2

The code of the form is as follows:
------------------------------------------------------------------------------------------

<?php
if (is_numeric ($_GET['order_number']))
{
if (isset ($_POST['submit']))
{
require_once ('conn_db.php');

$addi_info = $_POST['addi_info'];
$ordr_numb = $_GET['order_number'];

$query = "
insert into addi_info (ordr_numb, addi_info)
values ($ordr_numb, '$addi_info');
";

$result = @mysql_query ($query);
mysql_close ();
}
}
?>

<html>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
<textarea name="addi_info" value="<?php echo $_POST['addi_info']; ?>"></textarea>
<input type="submit" value="Save" name="submit">
</form>
</html>

------------------------------------------------------------------------------------------

So I need your help, in regards to how to receive values of different variables using $_GET and $_POST in the same form.
 
Try using:
Code:
 $_REQUEST

In place of your posts and gets when retrieving the data.


Let us know your results!

X
 
i suspect the form is being submitted with the post method and not the get method.

in this case, to use both get and post you need to set up your form something like this

Code:
<form action="webpage.php?order_number=value" method="post">
<input type="text" name="addi_info" />
<br/>
<input type="submit" name="submit" value="submit" />
</form>

this submits the form elements using POST to a webpage that has a querystring appended which you can access using the $_GET variable.

not sure why you would ever want to do this though. could you not just put the order_number into a hidden field inside the form? or store it in a session variable?
 
For jpadie:
But order_number is being sent by some other php page to this page.
 

The value gets sent before the user submits the form, which means you cna grab the value using the GET superglobal, and assign it to a hidden field.

Try adding a textbox and grabbing the value when you display the page trhe foirst time:
Code:
<input type=text name="order" value='<? echo $_GET['order_number'];?>'>

I'm pretty sure you'll be able to pick it up there and have it be resent when the form submits.






----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I agree with vacunita

could you not just put the order_number into a hidden field inside the form? or store it in a session variable?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top