-2

So instead of echo "Invalid specialization entered. Please check your spelling.";

I would like to echo "[THE TEXT THAT THE USER ENTERED] is not a valid spec."

All help appreciated. Tell me if I was not clear and if you need more info.

if (
$spec == "Protection" || $spec == "Arms" || $spec == "Fury" ||
$spec == "Shadow" || $spec == "Discipline" || $spec == "Holy" || 
$spec == "Frost" || $spec == "Fire" || $spec == "Arcane" ||
$spec == "Destruction" || $spec == "Demonology" || $spec == "Affliction" || 
$spec == "Subtlety" || $spec == "Combat" || $spec == "Assassination" || 
$spec == "Restoration" || $spec == "Feral" || $spec == "Balance" || $spec == "Guardian" ||
$spec == "Enhancement" || $spec == "Restoration" || $spec == "Elemental" ||
$spec == "Marksmanship" || $spec == "Beast Mastery" || $spec == "Survival")



{
    echo "<br>";
    echo "Valid spec entered.";
}


else {  
    echo "<br>";
    echo "Invalid specialization entered. Please check your spelling.";
}`
Dharman
  • 30,962
  • 25
  • 85
  • 135
Xellent
  • 3
  • 2
  • just concat $spec no? o.O – treyBake Oct 30 '19 at 09:38
  • 1
    If you have solved the problem, please consider adding an answer and accepting it so that your answer might help others in the future. I'm sure you've had the frustration of finding someone online that had the exact same problem as you but didn't go into any detail about how they solved it! – Rob Streeting Oct 30 '19 at 09:57

1 Answers1

0

First of all, instead of doing lots of || insert them in an array and check if the user inserted one of them through in_array:

$arrSpecs = array
(
    'Protection', 
    'Arms', 
    'Fury', 
    'Shadow', 
    'Discipline', 
    'Holy', 
    'Frost', 
    'Fire', 
    'Arcane', 
    'Destruction', 
    'Demonology', 
    'Affliction', 
    'Subtlety', 
    'Combat', 
    'Assassination', 
    'Restoration', 
    'Feral', 
    'Balance', 
    'Guardian', 
    'Enhancement', 
    'Restoration', 
    'Elemental', 
    'Marksmanship', 
    'Beast Mastery', 
    'Survival'
);

if(in_array($spec, $arrSpecs)
{
    echo "<br>";
    echo "Valid spec entered.";
}
else {  
    echo "<br>";
    echo "Invalid specialization entered ($spec). Please check your spelling.";
}`

Be aware that if the directive register_globals is set to off (As of default from PHP 4.2.0), you must get user input through $_GET or $_POST accordingly to the method used in your form, e.g.:

$spec = !empty($_GET['spec']) ? $_GET['spec'] : '';
user2342558
  • 5,567
  • 5
  • 33
  • 54
  • Ohh, that seems way easier. Still very new since I started the other day. Thanks for the info :) – Xellent Oct 30 '19 at 09:48