0

I'm trying to determine the value of $level based on the keyword user provide using If statement
but whatever was the user entry the value of $level always giving as 1
this is my code I need your help to find the error

<?php
$q1 = $_GET['q1'];
$con = mysqli_connect("localhost","FYP","123","FYP");
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));}

mysqli_select_db($con,"ajax_demo");
if ($q1=="Cite"||"Define"||"Enumerate"||"Index"||"Indicate"){
$level=1;}
elseif($q1=="Add"||"Approximate"||"Articulate"||"Associate")
{
$level=2;
}
elseif($q1=="Acquire"||"Adapt"||"Allocate"||"Alphabetize") 
{
    $level=3;
    }
elseif($q1=="Analyze"||"Analyse"||"Audit"||"Blueprint"||"Breadboard" ) 
{
    $level=4;
    }
elseif($q1=="Abstract"||"Animate"||"Arrange"||"Assemble" ) 
{
    $level=5;
    }
elseif($q1=="Appraise"||"Assess"||"Conclude"||"Counsel") 
{
    $level=6;
    }
else{$level=0;}
echo $level;
?>
3
Contributors
2
Replies
17
Views
2 Years
Discussion Span
Last Post by coreyavis
3
if ($q1=="Cite"||"Define"||"Enumerate"||"Index"||"Indicate"){

This is not the way to do it. Try:

if ($q1=="Cite"||$q1=="Define"||$q1=="Enumerate"||$q1=="Index"||$q1=="Indicate"){

Or

if(in_array($q1,array("Cite","Define","Enumerate","Index","Indicate"))){

Same goes for the other branches.

1

Another way:

switch($q1) {
    case 'Cite': case 'Define': case 'Enumerate': case 'Index': case 'Indicate':
        $level = 1;
    break;
    case 'Add': case 'Approximate': case 'Articulate': case 'Associate':
        $level = 2;
    break;
    case 'Acquire': case 'Adapt': case 'Allocate': case 'Alphabetize':
        $level = 3;
    break;
    case 'Analyze': case 'Analyse': case 'Audit': case 'Blueprint': case 'Breadboard':
        $level = 4;
    break;
    case 'Abstract': case 'Animate': case 'Arrange': case 'Assemble':
        $level = 5;
    break;
    case 'Appraise': case 'Assess': case 'Conclude': case 'Counsel':
        $level = 6;
    break;
    default:
        $level = 0;
    break;
}
echo $level;
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.