dtyson2000 Posted April 20, 2009 Share Posted April 20, 2009 Evening all... Quick question: I have what is probably a very simple script that compares a user's input with a set value to return a right or wrong answer. I have two functions, one to provide the initial value (not seen by user) and a field for user input. The second function compares the user's input with the initial value. The variables from the first function don't seem to be passing to the compare function. Here's an example of the code I'm dealing with: function get_value() { $initialval = "foobar"; ... <input type="textbox" name="user_value"> <input type="submit" name="submit"> } function compare() { if ($user_value == $initialval) { echo "right"; } else { echo "wrong"; } } $initialval = $_POST['initialval']; $user_value = $_POST['user_value']; if ($submit) { compare(); } else { get_values(); } It's probably something totally simple but I'm just not seeing it. Sorry if this is a little vague. I can clarify if there is a need for more. Thanks, in advance! Quote Link to comment https://forums.phpfreaks.com/topic/154946-solved-values-not-passing/ Share on other sites More sharing options...
Daniel0 Posted April 20, 2009 Share Posted April 20, 2009 http://php.net/manual/en/language.variables.scope.php Quote Link to comment https://forums.phpfreaks.com/topic/154946-solved-values-not-passing/#findComment-815037 Share on other sites More sharing options...
premiso Posted April 20, 2009 Share Posted April 20, 2009 I would suggest reading up on Variables Scope And make sure your form POST as the method and that isntead of $submit you use if (isset($_POST['submit'])) { isset to see what that does. EDIT: Dang it Dan. Well I have a bit more info so still posting Quote Link to comment https://forums.phpfreaks.com/topic/154946-solved-values-not-passing/#findComment-815041 Share on other sites More sharing options...
dtyson2000 Posted April 20, 2009 Author Share Posted April 20, 2009 Excellent. Thank you for pointing me in the right direction. I've got some reading to do now. It's time I get this right rather than sort of fumbling through these things by just moving things around until they work. Thanks, again! Quote Link to comment https://forums.phpfreaks.com/topic/154946-solved-values-not-passing/#findComment-815068 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.