0

Hi so I wanted to make a little quiz in php

if(isset($_POST['City'])) {

   echo "<strong>Answer nr1:<BR></strong>";

$cities= $_REQUEST["City"];

$odp = "Madrid" || "madrid";
//$odp = "Madrid" && "madrid";
//neither of OR/AND works here 

if($cities== $odp){

	echo "Your answer is <Font Color=#009900>correct</font> <P>";

}

elseif($cities== ""){

	echo "Please fill in this form<P>";

}

else{

	echo "Your answer is <Font Color=#FF0000>false</font> <P> ";

}

}

So yeah as you can see in my code i'm trying to let the php code here count the correct answers either lowercase and not.
So I'm wondering is there anothere method for or am I doing something wrong

any help would be appreciated

thanks & regards
Katsurou

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Katsurou
0

Below is a corrected version comparing case insensitive. So it will also work for MaDRiD

if(isset($_POST['City'])) {
 
   echo "<strong>Answer nr1:<BR></strong>";
 
$cities= $_REQUEST["City"];
 
$odp1 = "madrid";
//$odp = "Madrid" && "madrid";
//neither of OR/AND works here 
 
if(strtolower($cities)== $odp1){
	echo "Your answer is <Font Color=#009900>correct</font> <P>";
    } elseif($cities== ""){
	echo "Please fill in this form<P>";
    } else{
	echo "Your answer is <Font Color=#FF0000>false</font> <P> ";
    }
 
}
0
#
$odp = "Madrid" || "madrid";
if($cities== $odp)
{

This will result to something like this

if($cities== "Madrid" || "madrid")

this is a wrong statement....
it should come like this format

if( ($cities == "Madrid") || ($cities == "madrid"))
0

Thanks guys that helped me out alot =)
however I've stumbled on the next problem when I'm trying to see my answer with this lines of command

include ('test.php');


echo "<Font Color=#0000FF> <h1> Correct answers:</h1><p></font>";
echo "<h2>Answer nr1. <Font Color=#009900>$odp</h2><P></font>";

then I get to see "1"....
So my question is:
Can I solve it with another line of code or should I just write it down on echo?

thanks & regards
Katsurou

Edited by Katsurou: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.