...

View Full Version : Help me on oop in php code here



kingot
01-20-2012, 11:08 AM
Hi,

I have this code here using oop in php .Now i want the user to enter prime numbers specified in $this->prime..but the code is not working..Here is the code


<?php
class Prime{
public $prime;

public function CheckPrime(){
if(isset($_POST['prime']) && !empty($_POST['prime'])){
$this->prime=$_POST['prime'];

if(preg_match('/^[0-9]+$/', $this->prime)){

if($this->prime==Array(1,3,5,7,9,11,13,15,17,199,21,23,25,27,29,31)){
echo 'Ok';

}

}else{
echo 'Please enter numbers only';
}
}else{
echo 'Please enter a prime number ranging from 1-31 to test the programe';
}
}
}
$PrimeCheck= new Prime;
$PrimeCheck->CheckPrime();
?>

<form action="index.php" method="POST">
Enter a Prime number: <input type="text" name="prime"><input type="submit" value="Submit">
</form>

Thanks
Clement Osei

Wanna
01-20-2012, 11:34 AM
You are checking a string vs an array.


if($this->prime==Array(1,3,5,7,9,11,13,15,17,199,21,23,25,27,29,31)){

kingot
01-20-2012, 11:47 AM
Hi ,
Thanks much for your suggestion...!!

So how do i check it or do it to make it work.

Thanks
Clement Osei

Dormilich
01-21-2012, 09:10 AM
there are a lot of array functions. you could try in_array() (http://php.net/in-array)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum