westonm Posted April 28, 2011 Share Posted April 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/ Share on other sites More sharing options...
cssfreakie Posted April 28, 2011 Share Posted April 28, 2011 this $rtn = (_POST['Rtn']); must be $rtn = $_POST['Rtn']; hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207894 Share on other sites More sharing options...
westonm Posted April 28, 2011 Author Share Posted April 28, 2011 I can't type very well either - it is actually $rtn = ($_POST['Rtn']) Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207895 Share on other sites More sharing options...
Pikachu2000 Posted April 28, 2011 Share Posted April 28, 2011 Don't type code in; copy and paste it. It's near impossible to diagnose problems when it isn't the actual code. Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207896 Share on other sites More sharing options...
cssfreakie Posted April 28, 2011 Share Posted April 28, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207900 Share on other sites More sharing options...
fugix Posted April 28, 2011 Share Posted April 28, 2011 In your if statement. You are missing a closing parenthesis. Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207901 Share on other sites More sharing options...
fugix Posted April 28, 2011 Share Posted April 28, 2011 Also. Please use the code tag when inserting code Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207902 Share on other sites More sharing options...
westonm Posted April 28, 2011 Author Share Posted April 28, 2011 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". Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207906 Share on other sites More sharing options...
wildteen88 Posted April 28, 2011 Share Posted April 28, 2011 Where in script1 are you setting the $rtn variable Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207908 Share on other sites More sharing options...
Pikachu2000 Posted April 28, 2011 Share Posted April 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207913 Share on other sites More sharing options...
westonm Posted April 28, 2011 Author Share Posted April 28, 2011 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 . Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207919 Share on other sites More sharing options...
Pikachu2000 Posted April 28, 2011 Share Posted April 28, 2011 If you View ---> Source the output of script 1, is there an extra set of quotes in the value attribute in here? <input name="Rtn" type="hidden" value="<?php echo $rtn; ?>" /> Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207925 Share on other sites More sharing options...
fugix Posted April 28, 2011 Share Posted April 28, 2011 Your rtn index needs to be in single quotes Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207927 Share on other sites More sharing options...
westonm Posted April 28, 2011 Author Share Posted April 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207930 Share on other sites More sharing options...
Pikachu2000 Posted April 28, 2011 Share Posted April 28, 2011 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). Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1207941 Share on other sites More sharing options...
westonm Posted April 29, 2011 Author Share Posted April 29, 2011 Using the magic_quotes functions didn't help. I think I will take another approach and use session variables - maybe I will have better luck getting them to work. I guess we can mark this as solved. Quote Link to comment https://forums.phpfreaks.com/topic/235036-simple-coding-problem/#findComment-1208178 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.