When running this code it takes an XML input and parses the key values into variables to make a simple arithmetic calculation. I attempt manually validate the user input to ensure tags number1 and number2 are integers;
When echoing the variables they appear as integers but still meet the condition as if they aren't. Please let me know if you can see any problems.
<?php
$XML = “<?xml version='1.0' encoding='UTF-8'?>.
<arithmetic>
<operation>add</operation>
<number1>5</number1>
<number2>3</number2>
</arithmetic>”;
$equation = simplexml_load_string($XML); //loads xml into variable
$operation = $equation->operation; // loads operation into variable
$number1 = $equation->number1; // loads number1 into variable
$number2 = $equation->number2; //loads number2 into variable
// If the values entered are not numbers return error message
if(is_numeric($number1) != 1){
$number1 = "";
echo " Incorrect number 1 entered ";
}
if(is_numeric($number2) != 1){
$number2 = "";
echo " Incorrect number 2 entered ";
}
.....
is_numeric()does not test for integers. It tests whether a variable is an integer or a numeric string. You need to be more specific about what your code should accept as a number/integer.$_POST["XML"]with a hard-coded XML string that demonstrates the problem. (The fact that it's user input isn't really relevant.)