Jump to content

[SOLVED] Values not passing


dtyson2000

Recommended Posts

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!

 

Link to comment
https://forums.phpfreaks.com/topic/154946-solved-values-not-passing/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.