[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 10-23-2006, 11:21 PM   #1 (permalink)
NamePros Member
 
Join Date: Feb 2005
Posts: 159
31.00 NP$ (Donate)

alcapone is on a distinguished road


allow only numbers in a box

hi im looking for some way in php only to allow numbers in a text box say like in this part of a code here there is a way they can add certain marks in the reserve box that will give them more of what they sould get so need to beable to block all letters and signs and only allow 4 for the max length





PHP Code:
<?

include("html.php");

$x = array('#','-','+','&','a','n','d','w','h','e','r','"','$','%','&','^');

$y = array('','','','','','','','','','','','','','','','');

$reserves = str_replace($x, $y, trim($_POST['reserves']));

function
check_reserves($reserves) {

        
$i = '0';

        
$numz = array(1,2,3,4,5,6,7,8,9,0);

        
$reserves_check = preg_split('//', $reserves, -1, PREG_SPLIT_NO_EMPTY);

        foreach(
$reserves_check as $rc) {

                if(!
in_array($rc, $numz)) $i++;

        }

        if(
$i != '0') return 'bad';

        else return
'OK';

}

$pimp = mysql_fetch_array(mysql_query("SELECT code,status,alert FROM $tab[pimp] WHERE id='$id';"));   

$res = mysql_fetch_array(mysql_query("SELECT res FROM $tab[pimp] WHERE id='$id';"));

if (isset(
$_POST["alert"])) $alert=$_POST["alert"]; else $alert=0;

if((
$alert) && ($pmp["31"] == admin)){ mysql_query("UPDATE $tab[pimp] SET alert='$alert' WHERE id>0 "); }

if((
$reserves > 0) && (!preg_match ('[0-9]', $reserves)) && (!strstr($reserves,"+")) && (!strstr($reserves,"-")) && (!strstr($reserves,".")) && (!strstr($reserves,"/")) && (!strstr($reserves,"<")) && (!strstr($reserves,">")) &&  (!strstr($reserves,")")) &&  (!strstr($reserves,"(")) && (!strstr($reserves,"&")) && (!strstr($reserves,"@")) && (!strstr($reserves,"=")) && (!strstr($reserves,"*")) && ($reserves <= $res[0]))

//if(($reserves) != bad) && ($reserves > 0) && (!preg_match ('[0-9]', $reserves)) && (!strstr($reserves,"+")) && (!strstr($reserves,"-")) && (!strstr($reserves,".")) && (!strstr($reserves,"/")) && (!strstr($reserves,"<")) && (!strstr($reserves,">")) &&  (!strstr($reserves,")")) && (!strstr($reserves,"&")) && (!strstr($reserves,"@")) &&  (!strstr($reserves,"=")) && (!strstr($reserves,"*")) && ($reserves <= $res[0]))

{

$reserves = substr($reserves, 0, 4);

mysql_query("UPDATE $tab[pimp] SET trn=trn+$reserves, res=res-$reserves WHERE id='$id'");

}

$pmp = mysql_fetch_array(mysql_query("SELECT pimp,rank,nrank,city,networth,money,trn,res,condom,medicine,crack,weed,glock,shotgun,uzi,ak47,whore,thug,whappy,thappy,payout,crew,msg,atk,ivt,lowrider,attin,attout,lastattackby,lastattack,cmsg,rlauncher,hummer FROM $tab[pimp] WHERE id='$id'"));

$crw = mysql_fetch_array(mysql_query("SELECT name,founder,icon FROM $tab[crew] WHERE id='$pmp[21]';"));

$cty = mysql_fetch_array(mysql_query("SELECT name FROM $tab[city] WHERE id='$pmp[3]';"));

//31 = rocket launcher - hummer = 32

// turn info

$turnupdate = mysql_fetch_array(mysql_query("SELECT lastran FROM $tab[cron] WHERE cronjob='turns'"));

$game = mysql_fetch_array(mysql_query("SELECT speed,maxbuild FROM $tab[game] WHERE round='$gp'"));



function
sounds(){

global
$id, $tab, $site;

$sound = mysql_fetch_array(mysql_query("SELECT sounds,msg,atk FROM $tab[pimp] WHERE id='$id';"));

if(
$sound[0] != disabled)

  {

      if(
$sound[2] >= 1){?>

<body bgcolor="#FFFFFF">

<embed src="<?=$site[img]?>attack.swf" quality="high" width="1" height="1" menu="false" type="application/x-shockwave-flash" pluginpage="http://www.macromedia.com/go/getflashplayer"></embed>

<?}

  elseif(
$sound[1] >= 1){?>

<embed src="<?=$site[img]?>message.swf" quality="high" width="1" height="1" menu="false" type="application/x-shockwave-flash" pluginpage="http://www.macromedia.com/go/getflashplayer"></embed>

<?}

  }

}



$tw=$pmp[12]+$pmp[13]+$pmp[14]+$pmp[15]+$pmp[31];

$figure=$time - $pmp[28];

$count=round($figure / (60*60*24));

if((
$alert) && ($pmp[0] == admin || mod)){ mysql_query("UPDATE $tab[pimp] SET alert='$alert', newalert='1' WHERE id>0;"); }

$tillmax=number_format(((($game[1] - $pmp[6])/($game[0] * 6))*60)*60,0);

$tillmax = strtotime("+".str_replace(' ','',str_replace(',','',$tillmax))." seconds", $turnupdate[0]);



GAMEHEADER("Play the game");

?>

<table width="100%" align="center" cellspacing="0" cellpadding="12" border="0">

  <tr>

    <td align="center" valign="top"><table width="100%">

        <tr>

          <td valign="bottom"><table cellspacing="0" cellpadding="0">

              <tr>

                <?if($crw[2]){?>

                <td height="32" valign="bottom"><a href="gang.php?cid=<?=$pmp[21]?>&gp=<?=$gp?>"><img src="<?=$crw[2]?>" border="0" width="32" height="32"></a>&nbsp;</td>

                <?}?>

                <td><font color="7777CC">ranked</font>

                  <?=$pmp[1]?>

                  <font color="7777CC">in

                  <?=$cty[0]?>

                  ,</font>

                  <?=$pmp[2]?>

                  <font color="7777CC">national<br>

                  currently worth</font> $

                  <?=commas($pmp[4])?>

                  <?if($pmp[21] > 0){?>

                  <br>

                  <?if($pmp[0] == $crw[1]){?>

                  founder of

                  <?}else{?>

                  member of

                  <?}?>

                  <a href="gang.php?cid=<?=$pmp[21]?>&gp=<?=$gp?>">

                  <?=$crw[0]?>

                  </a>.

                  <?}?>

                  </small></td>

              </tr>

            </table></td>

          <td align="right" valign="bottom"><a href="mailbox.php?gp=<?=$gp?>">Open Mailbox</a><br>

            <?if($pmp[22] == 1){?>

            <font color="#66CCFF">you have 1 new message</font>

            <?}elseif($pmp[22] > 1){?>

            <font color="#66CCFF">you have

            <?=$pmp[22]?>

            new messages</font>

            <?}else{?>

            you have no new messages

            <?}?>

            <?if($pmp[23] == 1){?>

            <br>

            <font color="#7777CC">you have been attacked!</font>

            <?}elseif($pmp[23] > 1){?>

            <br>

            <font color="#7777CC">you have been attacked

            <?=$pmp[23]?>

            times!</font>

            <?}?>

            <?if($pmp[24] == 1){?>

            <br>

            <font color="#0066CC">you have a invitation!</font>

            <?}elseif($pmp[24] > 1){?>

            <br>

            <font color="#0066CC">you have

            <?=$pmp[24]?>

            new invitations!</font>

            <?}elseif($pmp[30] > 0){?>

            <br>

            <a href="cboard.php?cid=<?=$pmp[21]?>&gp=<?=$gp?>">

            <?=$pmp[30]?>

            new crew message</a>

            <?}?></td>

        </tr>

      </table>

      <?if($bigman){?>

      <font color="#7777CC" size="3">

      <?=$bigman?>

      </font><br>

      <?}?>

      <br>

      <font size="+1"><font color="3366FF">

      <?=commas($pmp[6])?>

      turns</font> and <font color="3366FF">$

      <?=commas($pmp[5])?>

      cash</font> on hand.</font> <br>

      Max turns in

      <?=countup($tillmax);?>

      <?if($takeout == reserves){?>

      <br>

      <form method="post" action="index.php?gp=<?=$gp?>">

        how many turns would you like to add? &nbsp;

        <input type="text" class="text" maxlength="4" size="7" name="reserves">

&nbsp;

        <input type="submit" class="button" value="apply">

      </form>

      <?}else{?>

      <?if($pmp[7] != 0){?>

      <br>

      <a href="?takeout=reserves&gp=<?=$gp?>"><font color="#FFFFFF">you also have</font>

      <?=commas($pmp[7])?>

      <font color="#FFFFFF">reserve turns</font></a></small>

      <?}?>

      <?}?>

      <br>

      <br>

      <table>

        <tr>

          <td><table>

              <tr>

                <td align="right"><font color="7777CC">glocks:</font></td>

                <td><?=commas($pmp[12])?></td>

              </tr>

              <tr>

                <td align="right"><font color="7777CC">shotguns:</font></td>

                <td><?=commas($pmp[13])?></td>

              </tr>

              <tr>

                <td align="right"><font color="7777CC">uzi's:</font></td>

                <td><?=commas($pmp[14])?></td>

              </tr>

              <tr>

                <td align="right"><font color="7777CC">AK-47's:</font></td>

                <td><?=commas($pmp[15])?></td>

              </tr>

              <tr>

                <td align="right"><font color="7777CC">rocketlaunchers:</font></td>

                <td><?=commas($pmp[31])?></td>

              </tr>

              <tr>

                <td align="right"><font color="7777CC">cigs:</font></td>

                <td><?=commas($pmp[8])?></td>

              </tr>

              <tr>

                <td align="right"><font color="7777CC">meds:</font></td>

                <td><?=commas($pmp[9])?></td>

              </tr>

              <tr>

                <td align="right"><font color="7777CC">moonshine:</font></td>

                <td><?=commas($pmp[10])?></td>

              </tr>

              <tr>

                <td align="right"><font color="7777CC">beer:</font></td>

                <td><?=commas($pmp[11])?></td>

              </tr>

              <?if($pmp[25] > 0){?>

              <tr>

                <td align="right"><font color="7777CC">truck:</font></td>

                <td><?=commas($pmp[25])?></td>

              </tr>

              <tr>

                <td align="right"><font color="#7777CC">rigs</font></td>

                <td><?=commas($pmp[32])?></td>

              </tr>

              <?}?>

            </table></td>

          <td width="50"></td>

          <td><table>

              <tr>

                <td><nobr>

                  <?=commas($pmp[17])?>

                  hustlers<br>

                  <font color="3366FF">

                  <?=$pmp[19]?>

                  %</font> <font color="7777CC">happy, with <br>

                  <?=commas($tw)?>

                  weapons total </nobr> </td>

              </tr>

            </table>

            <br>

            <table>

              <form method="post" action="set.php?gp=<?=$gp?>">

                <tr>

                  <td><nobr>

                    <?=commas($pmp[16])?>

                    bootleggers<br>

                    <font color="3366FF">

                    <?=$pmp[18]?>

                    %</font> <font color="7777CC">happy, at <br>

                    <input type="text" class="text" name="pay" size="3" value="<?=$pmp[20]?>">

                    % payout.

                    <input type="submit" class="button" name="setpay" value="set">

                    </nobr> </td>

                </tr>

              </form>

            </table></td>

        </tr>

      </table>

      <p><br>

        <font color="#7777CC">attacks in:</font>

        <?=$pmp[26]?>

&nbsp;<font color="#7777CC">out:</font>

        <?=$pmp[27]?>

        <br>

        <br>

        <?if($turnupdate[0]){?>

        you will receive <font color="#7777CC">

        <?=$game[0]?>

        </font> <font color="#7777CC">turns</font> in:

        <?=countup($turnupdate[0]+600)?>

        <br>

        <small>you can hold up to <font color="#7777CC">

        <?=commas($game[1])?>

        </font> <font color="#7777CC">turns</font>.

        <?}else{?>

        <i><b>Turns will start processing in less then 10 minutes...</b></i>

        <?}?>

        <?=sounds()?>

      </p>

     <? if($pmp[31] == admin){?>

      <form method="post" action="index.php?rid=<?=$rid?>">

        <b>admin panel:</b> alert all pimps:

        <input type="text" class="text" name="alert" size="20">

        <input type="submit" name="alertpimp" value="alert!">

      </form>

      <br>

      <?}?>

  </tr>

</table>

<?

GAMEFOOTER
();

?>
__________________
Hostile-Territory
alcapone is offline  
Old 10-24-2006, 06:23 AM   #2 (permalink)
NamePros Member
 
digifad's Avatar
 
Join Date: Aug 2006
Location: VA
Posts: 41
67.00 NP$ (Donate)

digifad is on a distinguished road


Not sure I follow your request, but why not implement a Javascript validation script so the form cannot be submitted until only numbers (max of 4) are present in the form.
digifad is offline  
Old 10-25-2006, 10:26 AM   #3 (permalink)
NamePros Member
 
Join Date: Mar 2006
Location: USA - RI
Posts: 49
216.70 NP$ (Donate)

Horranus is an unknown quantity at this point


Quote:
Originally Posted by digifad
Not sure I follow your request, but why not implement a Javascript validation script so the form cannot be submitted until only numbers (max of 4) are present in the form.

Because JS validation is very easy to bypass.


Off the top of my head a preg_match function might do it.
Horranus is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 03:30 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85