Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2011
    Posts
    114
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Help me on oop in php code here

    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 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

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    You are checking a string vs an array.
    PHP Code:
    if($this->prime==Array(1,3,5,7,9,11,13,15,17,199,21,23,25,27,29,31)){ 

  • #3
    Regular Coder
    Join Date
    Feb 2011
    Posts
    114
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hi ,
    Thanks much for your suggestion...!!

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

    Thanks
    Clement Osei

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,335
    Thanks
    13
    Thanked 348 Times in 344 Posts
    there are a lot of array functions. you could try in_array()
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •