I need to make echo for each next situation

if points typed is <0 echo can't be negative number

if points typed is 0 echo clean 0

if points typed is > 50 echo you passed test

if points typed is 100 echo you finished with best result

and all of this I made easy but thing is in next one

if points typed is text echo points can't be text

problem is, whenever I type text I get echo both for < 0 and if(preg_match($pattern,$points))

and removing - from pattern doesn't solve the problem

here is code

<?php
$select=$_POST['select'];
if(isset($select) and $select=="submit"){
$points=$_POST['points'];




if ($points < 0){
echo "Points can't be negative"; }

$pattern = "/^(?:100-|\d{1,2})$/";
if(preg_match($pattern,$points))
{


if ($points == 0) {
echo "Clean 0"; }

if ($points > 50 && $bodovi < 100) {
echo "You passed test"; }

if ($points == 100) {
echo "You finished with best result"; }

}else { 
echo "Points can't be text";
}



}



?>

<form method=post name=points action=''><input type=hidden name=select value=submit>

<table border="0" cellspacing="0" >
<tr>
<td><div align="right">
<p>Number of points:</p>
</div></td>

<td>
<input type=text name=points size=15 > 
</td></tr>

<td>
<input type=submit value=Ispisi>
</td>
</table>
</form>

does anyone know why are those two conflicting?

if ($points < 0){
echo "Points can't be negative"; }

and

$pattern = "/^(?:100-|\d{1,2})$/";
if(preg_match($pattern,$points))
{

Why don't you do it simple way:

// first check if it is or isn't a number
if(!is_numeric($points)) {
    echo "Points can't be text";
// then try all possible values
} elseif($points == 0) {
    echo "Clean 0";
} elseif($points > 0 && $points <= 50) {
    echo "You did not pass";
} elseif($points > 50 && $points < 100) {
    echo "You passed test";
} elseif($points == 100) {
    echo "You finished with best result"; }
}

And beware: on line 20 you are using two variables for comparison: $points and $bodovi. Seems like a typo.

I tried that in begining, it execute 2 echo's for text and for = 0 so its like
also for negative numbers I get 2 echo's

Points can't be negative.Cista 0

and

Points can't be text.Clean 0

and ye bodovi, I just translate to points, to be easier to understand, I do it on my language, I forgot to translate everything not big deal

P.S hey broj1, long time no seen, glad to see you!

I tried that in begining, it execute 2 echo's for text and for = 0 so its like Points can't be text.Clean 0

What did you input to get these two echo statemens?

I tested my code and it works OK. It is important to have the exact series of if statements.

hey broj1, long time no seen, glad to see you!

:-) Thank you. Same here.

if I type for example erwgwerg I get echo Can't be textClean 0

and if I type -23 I get echo points can't be text. Points can't be negative

P.S I fixed, did't saw right order as you posted, I did some on my own, I just edited your 0 - 50 statement to < 0, those are all I need

Thanks mate, you solved my problem

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.