Jump to content

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

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.