Jump to content

Recommended Posts

I am thining this will be pretty simple for someone to help me with, I have been hassling with it for several hours and really feel dumb that I can't get it to work. 

Here is the problem -

I have one script wherein I have a form that passes a variable using Post method. 

I have previously assigned a value "A" to a variable $rtn

the input is:

<input name="Rtn" type="hidden" value="<?php echo $rtn; ?> />

 

In the script that I am calling I first get the value of the variable:

 

$rtn = (_POST['Rtn']);

 

then there is other stuff goin on and I come to an if stmt:

 

if ($rtn == "A" {

  do some stuff

} else {

  echo $rtn;

}

 

It will never get into the do some stuff - it always falls through to the else the output is

\'A\'

 

I have tried to use double quotes, single quotes, used stripslasches and addslashes funtions, trim, and various combination of all of these. 

Nothing I do seem to get me into the first part of the if stmt, to do some stuff. 

Link to comment
https://forums.phpfreaks.com/topic/235036-simple-coding-problem/
Share on other sites

I can't type very well either - it is actually

$rtn = ($_POST['Rtn'])

 

well if that is the code it's missing a semicolon -> ;

it should be

$rtn = $_POST['Rtn'];

anyway are you sure you even have a $_POST value set?

Ok sorry - Am copying the code;

 

Script 1

<form action="dataProcess.php" method="POST" id="Email">

...

<input name="Rtn" type="hidden" value="<?php echo $rtn; ?>" />

 

Script 2

...

$rtn = ($_POST[Rtn]);

 

...

if ($rtn == "A") {

              header ("Location: http://www.***.com/foundation/MeetBoard.php");

              exit(0);

} else {

                echo "Fall to else ";

                echo $rtn ;

                echo gettype($rtn);

}

 

Output

Fall to else \'A\'string

 

When it works, the else clause will send me off to the home page.

 

Yes I am getting the variable to the second script - The else clause is doing the output of the three lines, showing me it is in the else clause, the value of the $rtn variable and the type.  The value of $rtn is showing the backslashes and I am thinking that is why it won't equal to the comparison value of "A". 

I'd say it looks as though magic_quotes_gpc = On in your php.ini file, which it really shouldn't. If you can disable it, you should consider doing so as long as your other code is properly written to escape data when needed for db queries. If you can't disable it, you can run incoming form data through a function to get rid of unneeded slashes.

Ok sorry - let me try to get this right - here is code

 

Script 1

 <form action="dataProcess.php" method="POST" id="Email">
...
<input name="Rtn" type="hidden" value="<?php echo $rtn; ?>" />

 

Script 2

...
$rtn = ($_POST[Rtn]);

...
if ($rtn == "A") {
              header ("Location: http://www.***.com/foundation/MeetBoard.php");
              exit(0); 
} else {
                 echo "Fall to else ";
                 echo $rtn ;
                 echo gettype($rtn);
}

 

The output is coming from the else clause in the if stmt. 

it reads

Fall to else\A\string

So it is getting the value of "A" but has the backslashes that I think are preventing it from compaing . 

 

 

To Pikachu2000 -

That could be the problem - All of the other pages in the site were developed with Dreamweaver and has a function to take care of it.  I haven't understood exactly what it did but I guess I need to get into that to understand what it is not doing.  I had thought the stripslasched function would do the same thing, but maybe not.  I am on a shared newtork and do not have access to change php.ini settings, so will have to live with how it is set up now. 

OK. If you can't change the php.ini file, you should be checking for get_magic_quotes_gpc() and if it returns TRUE, use stripslashes() on the data (and mysql_real_escape_string() if it's going into a DB query string).

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.