Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default [PHP] Little Help?

    Okay,

    I need some code where if a user puts in a "-" sign into the system, it wil bounce back with

    Negative numbers are not allowed.


    Ive tried both..

    PHP Code:
    <?php
    if($bet "-")
    die(
    'Cannot bet a negative number of credits...!<meta http-equiv="refresh" content="2;url=game_hl.php" /><br />You will be redirected!');
    ?>
    And

    PHP Code:
    <?php
    if(preg_match("-",$bet))
    die(
    'Cannot bet a negative number of credits...!<meta http-equiv="refresh" content="2;url=game_hl.php" /><br />You will be redirected!');
    ?>
    Any ideas?

    Moved by Agesilaus (Forum Moderator) from Designing and Development: Please post in the correct forum next time.
    Last edited by Agesilaus; 04-01-2008 at 11:49 PM.
    Coming and going...
    Highers are getting the better of me

  2. #2
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    PHP Code:
    <?php
    if( eregi("-"$bet) )
    {
        die(
    'Cannot bet a negative number of credits...!<meta http-equiv="refresh" content="2;url=game_hl.php" /><br />You will be redirected!');
    }
    ?>

  3. #3
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Ooh ty, that works

    +REP if i can.
    Coming and going...
    Highers are getting the better of me

  4. #4
    Join Date
    Jul 2005
    Posts
    1,653
    Tokens
    50

    Latest Awards:

    Default

    Just use is_numeric

  5. #5
    Join Date
    Jun 2005
    Posts
    2,688
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:

    if($bet == "-") die("Something"); 
    lol..

    You used = which is only an assignment operator in PHP. == is to compare

  6. #6
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    surely == would mean that the character ("-") is the only one in the field?
    Coming and going...
    Highers are getting the better of me

  7. #7
    Join Date
    Jan 2007
    Posts
    651
    Tokens
    0

    Default

    Quote Originally Posted by MrCraig View Post
    surely == would mean that the character ("-") is the only one in the field?
    Correct.

    There are loads of ways of doing it.
    PHP Code:
    if ($bet '0'){
    die(
    'No negative bets!');

    Is a way of doing it.
    James


    Connected to reality through a proxy server.

  8. #8
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Ooh, never thought of that

    +REP =]
    Coming and going...
    Highers are getting the better of me

  9. #9
    Join Date
    Apr 2006
    Location
    Salford
    Posts
    2,108
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    <?php if($fetch->bet == "-"){
    echo 
    "Negative numbers are not allowed.";} ?>

  10. #10
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Eh.

    Whats with the $fetch-> ?

    And surely that would mean that it would only echo the command if the only value in the field was a - sign.
    Coming and going...
    Highers are getting the better of me

Page 1 of 2 12 LastLast

Posting Permissions

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