Simple game to test user input for a secret word is not working as expected. Nothing is returned to the screen when conditions are evaluated. I'm pretty sure it is simple problem but most of the questions/answers here are more complicated than I believe looking for.
This is what i'm working with. Ask user to enter word of exactly 9 characters and it must include the @ symbol. All keyboard characters are live too. Echo to user if the requirement isn't met or success if it does.
<?php
if (!isset($secret_word)) {
$secret_word = ''; }
/* prompt user to enter a secret word that contains 9 characters of which one must be @ sign and all keyboard characters are allowed. if the secret word isn't correct output what is wrong with the word. */
#get user input
$secret_word = filter_input(INPUT_POST, 'secret_word');
$wordTest = secretWord();
function secretWord() {
if (strlen($secret_word) < 9) {
echo "Secret word is too short!"; }
if (strlen($secret_word) > 9) {
echo "Secret word is too long!"; }
if (!preg_match("@", $secret_word)) {
echo "Secret word must contain @ sign"; }
if (strlen($secret_word) == 9 && preg_match("@", $secret_word)){
echo "$secret_word contains 9 characters and one sign.";}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="q4.css">
<title>Untitled Document</title>
</head>
<body>
<div class="header">
<header><h1>Secret Scroll Game</h1></header>
</div>
<div class="output">
<p><?php echo $wordTest(); ?></p>
</div>
<div class="link">
<a href="q4_index.html">Back To Homepage</a>
</div>
</body>
</html>