Jump to content

POST variables being sent as GET variables


Herman2

Recommended Posts

Hello everybody.

 

Hope you can help me out. Searched Google whole day off finding the answer to my problem.

 

The problem is, that for a basic form with a post method, the variables are being send as get variables :S. I have enough experience with forms and sending variables through post and get, even together at the same time in one form. I am working on a new site, on a new server, so I think it's got be something to do with the php settings I think, but can't find what it is. Maybe its a simple thing, that's why I post it here...

 

Hope you understand my problem.

 

Just in case, my very basic form code:

 

<form name="vrm" method="post" action="index.php">
            <table class=tmax style='width:350px;'>
            <tr><td width=150>Username</td><td><input style='width:200px;' type=text name=username value="<?php echo $username;?>" /></td></tr>
            <tr><td>Email</td><td><input style='width:200px;' type=text name=username value="<?php echo $email;?>" /></td></tr>
            <tr><td></td><td align=right><input type=submit value=Save class=button /></td></tr>
            </table>
</form>

Link to comment
Share on other sites

no, your sending as post

 

method="POST" or method="GET" is what determines how it's sent...... also I'm interesting in how you think your sending both in the same form.......

 

for reference you accept the info in php using either

 

$_POST['username'] or $_GET['username'] respectively I would not recommend using $_REQUEST... besides wasn't $_REQUEST removed?

Link to comment
Share on other sites

what makes you think this is happening?  please give a detailed example.

 

When I hit the save button I see first of all the two variables, username and email, as get variables in the adress bar. Its the same script I use on other servers, so what does it make different than the old way.

 

If you are using REQUEST it may be that the request_order in php.ini is not the same on the new host server. Showing the code in index.php where you deal with the form data might help some.

 

I use the normal $_POST[] and $_GET[] methods. There is nothing in index.php, I even tried with an empty php file with nothing more than

 

<?php
echo $_POST['username'];
?>

 

So there is basically nothing wrong with my (too simple) script, thus I couldnt make it else than some settings of php?? But which one? Or am I doing something wrong with the script because of php 5 instead of 4?

 

(its just nothing more code than I gave you above... :S)

Link to comment
Share on other sites

I know enough of php to know I am sending as post with method=post...

 

The weird thing is, that with this method=post I get the variables username and email as get variables inside the adres bar.... Like this:

 

index.php?username=value1&email=value2

 

Thats the weird thing.

 

 

no, your sending as post

 

method="POST" or method="GET" is what determines how it's sent...... also I'm interesting in how you think your sending both in the same form.......

 

for reference you accept the info in php using either

 

$_POST['username'] or $_GET['username'] respectively I would not recommend using $_REQUEST... besides wasn't $_REQUEST removed?

Link to comment
Share on other sites

Best guess is you have nested <form> tags and the first one does not have a method= attribute (the default is GET.)

 

The only way to get a quick answer to what is going on with your form is if you post all the actual code for your form page.

Link to comment
Share on other sites

I have to run for a bit so I can't sit and wait for an answer here but.... this is the confusing bit

 

I have enough experience with forms and sending variables through post and get, even together at the same time in one form

 

no you cannot send both in the one form, which means you must be putting multiple forms inside each other which means your probably getting messed up code, which to me says the problem is right there

Link to comment
Share on other sites

primefalcon:  I have sent both in a form before.  If there is a querystring in the ACTION attribute they show up as $_GET variables.  I discovered this when I was trying to add some (apache) mod_rewrite and using ACTION="".  If the re-write gives the browser the url with a querystring and the ACTION="", then you get that querystring when you POST the form.

 

Just thought I'd mention it.  As to the OP's problem, I have to agree with you, probably another form that was not closed.

Link to comment
Share on other sites

primefalcon:  I have sent both in a form before.  If there is a querystring in the ACTION attribute they show up as $_GET variables.  I discovered this when I was trying to add some (apache) mod_rewrite and using ACTION="".  If the re-write gives the browser the url with a querystring and the ACTION="", then you get that querystring when you POST the form.

 

Just thought I'd mention it.  As to the OP's problem, I have to agree with you, probably another form that was not closed.

 

it's not that you are "sending" both, but just retrieving both.  there can only be one method of transfer as set by a form, method="post" or method="get".  however, you are right in that you can retrieve values form a query string that was sent as the form action, by way of using $_GET, even when that same form was sent using a post method.

 

but in order to have two methods of transfer, as some people are referring to, you'd have to do something like method="get,post", which obviously isn't going to work.

 

just to clarify.

Link to comment
Share on other sites

I want to say thanks  to everybody who has replied to my problem. After reading all these comments I created a new file just with nothing more than the form. There I found out that it worked (feel stupid now). The problem was indeed a not closed form in another basic file, forgot to edit that one... (the form was included in my basic system with nothing more than a login form, that login form I forgot to close...

 

But the good thing is, now I've learned what happened so next time I will look into my other code to find out where my not-closed form is :P

 

Thank you all!

 

I have to run for a bit so I can't sit and wait for an answer here but.... this is the confusing bit

 

I have enough experience with forms and sending variables through post and get, even together at the same time in one form

 

no you cannot send both in the one form, which means you must be putting multiple forms inside each other which means your probably getting messed up code, which to me says the problem is right there

 

I haven't used the right terminology, no you can't send a form with get and post at the same time as a method, but you can send get variables at the moment you send post variables by adding them to the action=""

 

like this:

 

<form method="post" action="index.php?id=value">
<input type=text name=username>
</form>

 

In this way you can get the id by GET and username by POST...

Link to comment
Share on other sites

Glad everything is sorted, and yup you can definitely do that :-) and though technically it's not sending the the data in the form it is send both at the same time (the get data is still a part of where to send the post data), I think it is something a lot of us do without thinking about it

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.