Problem: A Prime number program

Hello friends,
please dont feel disappointed by my question. Im not too perfect in php.
Im battling at writing a prime number program. I did it to this point: if the textbox is empty, it tells the user to input a number. When a number less than 2 is entered, it tells the user to input a higher value. Now my problem is, when i input a greater than 2 number like 4, it still tells me its a prime number. Please help me.

The source code is:

<?php

//collects the number entered by user.

$num = $_POST['num'];

if(empty($num)){
die("ERROR: Please enter a number.");
}

if($num<2){
echo "This is no prime number.";
}
elseif($num %= 1 && ...){ // i have problems here completing this line of code.
echo "This is a prime number";
}
else{
echo "This is NOT a prime number";
}

?>

------------------
Thanks,
Golden Waters.
 

conor

New Member
something like this should work:

Code:
        if( $num % 2 == 0 )
                echo $num . ' is a prime number';
        else
                echo $num . ' is not a prime nuber';
 
Top