1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need 2 min of help with PHP

Discussion in 'BlackHat Lounge' started by xthoms, Feb 18, 2011.

  1. xthoms

    xthoms Regular Member

    Joined:
    Sep 14, 2010
    Messages:
    280
    Likes Received:
    99
    Sorry if it was started in the wrong section. Please move it if it's the case. I was just looking at the categories in the Main menu bar in the left side not realising there's a programming section. Sorry!

    I've written a code for a second degree equation solver but I need to add that it should tell me when the values entered are not number and it should then echo a simple "This is not possible" or something, but I've looked around and can't figure out how to do it.

    Here's the code
    http://knowledgehunter.org/exercice.txt

    Here's it in PHP
    http://knowledgehunter.org/exercice.php

    Help will be rewarded with thanks and rep =)

    Thanks a lot!
     
    Last edited: Feb 18, 2011
  2. f0rked

    f0rked Registered Member

    Joined:
    Jan 25, 2009
    Messages:
    71
    Likes Received:
    64
    This should be in the PHP section, but there is a function called is_numeric that should do what you need.

    PHP:
    <?php
    $a 
    1;
    if(
    is_numeric($a)){
    echo 
    "yup";
    }else{
    echo 
    "nope";
    }
    ?>
     
    • Thanks Thanks x 1
    Last edited: Feb 18, 2011
  3. xthoms

    xthoms Regular Member

    Joined:
    Sep 14, 2010
    Messages:
    280
    Likes Received:
    99
    I tried using that code but I could not get it to work. It kept sending me error messages for some reason. I am JUST learning to program so my knowledge is very limited, but I had come to that conclusion, that it is_numeric should be able to do what I want
     
  4. The Scarlet Pimp

    The Scarlet Pimp Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 2, 2008
    Messages:
    788
    Likes Received:
    3,129
    Occupation:
    Chair moistener.
    Location:
    Cyberspace
    you can use j.script to auto-delete anything that isn't a number. i use it on my web pages to prevent people from entering letters when they should enter numeric values.

    for example, i have a text window that asks people to enter their phone number. if they enter something like 'don't want to say' instead of '(555) 708-1212' their
    info gets auto-deleted as soon as they move to the next text window.
     
    • Thanks Thanks x 1
  5. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    1) "elseif" is one word in php.

    2) put an exit; after each echo "This is not a number";

    3) Your braces are all fucked up

    4) Post the specific error messages you're getting
     
    • Thanks Thanks x 1
  6. xthoms

    xthoms Regular Member

    Joined:
    Sep 14, 2010
    Messages:
    280
    Likes Received:
    99
    Thanks a lot. I got it to work. I know the code is quite bad but seeing as I've only had a few lessons it will do =)