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;
?>
Member Avatar for diafol
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.

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;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.