Can I get some php help? via /r/learnprogramming


Can I get some php help?

Novice Php user. Working on making a quiz that asks the user what the capital of a state is. This is what I have so far. But how do I make it to where it only asks one question at a time like a quiz without displaying the validation like "correct" or "wrong answer"? I need it to ask a the question " what is the capital of "{state}?". The user answers and then it asks the same question but with next state in the array. Ive tried everything and looked everywhere but still can figure it out. Is there anyone that help me? The code I have now gives me this

"What is the capital of Georgia?Wrong! Next Question.What is the capital of Arizona?Wrong! Next Question.What is the capital of Michigan?Wrong! Next Question.What is the capital of Idaho?Wrong! Next Question.What is the capital of Nevada?Wrong! Next Question."

 $capitals['Georgia'] = "Atlanta"; $capitals['Arizona'] = "Phoenix"; $capitals['Michigan'] = "Lansing"; $capitals['Idaho'] = "Boise"; $capitals['Nevada'] = "Carson City"; $states = array_keys($capitals); $cities = array_values($capitals); foreach($capitals as $state => $capital){ echo "What is the capital of {$state}?"; $answer = readline(); if($answer === $capital){ echo 'Correct!'; } else{ echo 'Wrong! Next Question.'; } } 

?>

 <form action="capitals.php" method="post"> Answer: <input name="answer" type="text" placeholder="Answer"/> <input name="submit" type="submit" value="Submit"/> </form> 

Submitted July 16, 2017 at 02:36PM by angstromlevy
via reddit http://ift.tt/2vrsC9z

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s