Jump to content
xisto Community
SilverFox1405241541

Wierd Problem With $_post/$_get/$_request

Recommended Posts

I'm having a bad problem and no idea how to fix it...it's setting my back on my PHP work.

I have 7 if statements that do something depending on what $_POST['command'] is, it works for the first 6th and on the last one it adds a 1 (only ads the 1 at the end IF its the one in the if statement).

Example of the failing line:

if ($_POST['final'] == 'yes' AND $_POST['command'] == 'lol' AND $_POST['action'] == 'cmd'){
The other ifs are like that, just $_POST['command'] == other things.

Those if statements work. It does this with $_GET and $_REQUEST. It does this no matter what I put in the statement and if i make it blank it puts a 1 anyways.

I even put this before the if statement:
$whattostrp2 = array("1");  $_POST['command']= str_replace($whattostrp2, "", "$_POST[command]");
STILL adds a 1. I have it echoing the $_POST['command'], hence how I know this. What I don't understand its WHY it does this ONLY on the 7th if statement and not the others. I tried to make it where $_POST['command'] == 'lol1' and it adds ANOTHER 1.

It also does this with else if and elseif. If I redo the IF statement like this:
if ($_POST['command'] == 'lol'){

It still fails.

Any ideas? This is really bugging me and I have found NOTHING on it.
Edited by SilverFox (see edit history)

Share this post


Link to post
Share on other sites

Can you paste the whole code or rather the rest of the if statements? So you trying to get the $_POST data from a form? And for the 'command', what is it? eg. Radio, text input, drop down box. If you could put some codes from the form till the form action and then the if else statement. Might get some clues on why this happen.

Share this post


Link to post
Share on other sites

@kelvinmaki: Its a text box, and final/action are hidden. The reason I didn't post the whole code is its around 50 lines long or so and if I was to have ALL the if statements around 200 lines. I know its relatively small but its a lil big for a forum post. Also its not an error in the html form, I know how to make an html form correctly and it ONLY happens on the FINAL if statement (although I never tried adding an extra one to see if its the 7th or the last). I'll post more of the code if I can get around to it, I'm pretty busy right now trying to finish this update and working around the house.@ether: I'll try that out, what I did was just ditch it above 6 for now.

Edited by SilverFox (see edit history)

Share this post


Link to post
Share on other sites

I'm having a bad problem and no idea how to fix it...it's setting my back on my PHP work.
I have 7 if statements that do something depending on what $_POST['command'] is, it works for the first 6th and on the last one it adds a 1 (only ads the 1 at the end IF its the one in the if statement).

Example of the failing line:

if ($_POST['final'] == 'yes' AND $_POST['command'] == 'lol' AND $_POST['action'] == 'cmd'){
The other ifs are like that, just $_POST['command'] == other things.

Those if statements work. It does this with $_GET and $_REQUEST. It does this no matter what I put in the statement and if i make it blank it puts a 1 anyways.

I even put this before the if statement:
$whattostrp2 = array("1");  $_POST['command']= str_replace($whattostrp2, "", "$_POST[command]");
STILL adds a 1. I have it echoing the $_POST['command'], hence how I know this. What I don't understand its WHY it does this ONLY on the 7th if statement and not the others. I tried to make it where $_POST['command'] == 'lol1' and it adds ANOTHER 1.

It also does this with else if and elseif. If I redo the IF statement like this:
if ($_POST['command'] == 'lol'){

It still fails.

Any ideas? This is really bugging me and I have found NOTHING on it.
Do you try to do the same thing but instead of using the operator '==' use the operator '===' that also compares if both sides are of the same type.

Best regards,

Share this post


Link to post
Share on other sites

Also, you said you tried

$whattostrp2 = array("1");  $_POST['command']= str_replace($whattostrp2, "", "$_POST[command]");
If I remember correctly, you cannot, at least in PHP 5, which we now use, and I'm pretty sure in PHP 4 as well, assign to $_POST, $_GET, $_REQUEST, and the like. So you would have to assigne $_POST['command'] to something else, then try to strip them. Also, how do you know it is adding a one? What debugging code for that check do you have?
~Viz

Share this post


Link to post
Share on other sites

@kelvinmaki: Its a text box, and final/action are hidden. The reason I didn't post the whole code is its around 50 lines long or so and if I was to have ALL the if statements around 200 lines. I know its relatively small but its a lil big for a forum post. Also its not an error in the html form, I know how to make an html form correctly and it ONLY happens on the FINAL if statement (although I never tried adding an extra one to see if its the 7th or the last). I'll post more of the code if I can get around to it, I'm pretty busy right now trying to finish this update and working around the house.

SilverFox,

Let me get it correctly, you are passing a textbox over by the $_POST, and only at the last IF statement, you are getting the value 1.
So at the last IF statement, what you printed out is value 1 am I right.
It could be an empty array in the $_POST. When its an empty array, using echo, print or print_r, it will gives you a 1.
If that's no the problem, you can pm me with the html codes and the script of IF ELSE. I can test it in my system. That will be easy to debug rather than speculating all the possible reason.

CHEERS

Share this post


Link to post
Share on other sites

@tav: That is a good idea, I had to do that before. I'll try that out.@vizy: Yes but it still shouldn't do that (add the 1 without the stripping).
@Kelvin: Its not empty. I'll get back on this. Really busy.

Ok, but i think that if you post your complete code it would be better to us to help you.

Best regards,

Share this post


Link to post
Share on other sites

Yeah, I would like to see the full code too, with html, the post data which is sent and how it is gathered and etc. I think it is just a logical mistake somewhere in the code or just it is one of those things which you can't see even if it is so visible ;] I remember I spend some time on such stupid errors, but after a week I just checked with my clear head and found it very fast, in fact, it happened much more times than one :P

Share this post


Link to post
Share on other sites

Yeah, I would like to see the full code too, with html, the post data which is sent and how it is gathered and etc. I think it is just a logical mistake somewhere in the code or just it is one of those things which you can't see even if it is so visible ;] I remember I spend some time on such stupid errors, but after a week I just checked with my clear head and found it very fast, in fact, it happened much more times than one :P

Agreeded. I've not been coding for long but sometimes do make such mistake that are so visible. And when I show my codes to someone else, they just find out the root cause within a few minutes. So if you want to share your codes, just paste it. Definitely someone will be able to spot something. :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.