bookmark - Wierd Problem With $_post/$_get/$_request

Wierd Problem With $_post/$_get/$_request

 
 Discussion by SilverFox with 11 Replies.
 Last Update: August 7, 2007, 3:56 pm
 
bookmark - Wierd Problem With $_post/$_get/$_request  
    
free web hosting
 
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:

CODE

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:

CODE

$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:

CODE

if ($_POST['command'] == 'lol')
{


It still fails.

Any ideas? This is really bugging me and I have found NOTHING on it.

Wed Aug 1, 2007    Reply    New Discussion   


What's it adding 1 to?

Thu Aug 2, 2007    Reply    New Discussion   

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.

Thu Aug 2, 2007    Reply    New Discussion   

Just a troubleshooting hunch...rewrite it this way:

CODE

if ( ($_POST['final'] == 'yes') AND ($_POST['command'] == 'lol') AND ($_POST['action'] == 'cmd') )

Fri Aug 3, 2007    Reply    New Discussion   


@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.

Fri Aug 3, 2007    Reply    New Discussion   

QUOTE (SilverFox)

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:

CODE

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:

CODE

$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:

CODE

if ($_POST['command'] == 'lol')
{


It still fails.

Any ideas? This is really bugging me and I have found NOTHING on it.
Link: view Post: 108490

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,

Fri Aug 3, 2007    Reply    New Discussion   

Also, you said you tried

QUOTE (SilverFox)

CODE

$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

Sat Aug 4, 2007    Reply    New Discussion   

QUOTE (SilverFox)

@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.
Link: view Post: 108584


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

Sat Aug 4, 2007    Reply    New Discussion   

@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.

Tue Aug 7, 2007    Reply    New Discussion   

QUOTE (SilverFox)

@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.
Link: view Post: 108761

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

Best regards,

Tue Aug 7, 2007    Reply    New Discussion   

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

Tue Aug 7, 2007    Reply    New Discussion   

QUOTE (Quatrux)

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
Link: view Post: 108777


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

Tue Aug 7, 2007    Reply    New Discussion   

Quickly Post to Wierd Problem With $_post/$_get/$_request  w/o signup Share Info about Wierd Problem With $_post/$_get/$_request  using Facebook, Twitter etc. email your friend about Wierd Problem With $_post/$_get/$_request Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

Top 10 Php Framework List of PHP Framework  Top 10 Php Framework List of PHP Framework (0) (5) Structure Of A Switch   Structure Of A Switch