FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Form and PHP problem





Nehallyn
So I have this name generator, and it has a form that tells the script how many names to generate at once. Only no matter what I pick, it always generates only one. I can't see where the problem is at all.

Code:
<form action="index.php" method="POST" name="frmControls">
    <p>Number to Generate: <select name="selGenCount" size="1"> <strong>Is Broken at the moment! Only one at a time!</strong>
<?php
   if ($selGenCount==1)
   {
      print("<option value=1 selected>1</option>");
   }
   else
   {
      print("<option value=1>1</option>");
   }

   for ($intLooper=5;$intLooper<55;$intLooper+=5)
   {
      if ($selGenCount==$intLooper)
      {
         print("<option value=$intLooper selected>$intLooper</option>");
      }
      else
      {
         print("<option value=$intLooper>$intLooper</option>");
      }
   }

?>
    </select>
   <input type="submit" name="subGenerate" value="Generate"></p>
</form>
<HR><?php



   function GetWord($intNeedGet,$intAlreadyHave)
   {
      global $intWordCode;
      
      $bStop = false;
      
      do
      {
         if (count($intWordCode)==1)
         {
            $intReturnNumber=0;
         }
         else
         {
            $intReturnNumber=rand(0,count($intWordCode)-1);
         }

         $bStop=true;

         if (($intWordCode[$intReturnNumber] & $intNeedGet)!=$intNeedGet)
         {
            $bStop=false;
         }

         for ($intLooper=0;$intLooper<count($intAlreadyHave);$intLooper++)
         {
            if ($intReturnNumber==$intAlreadyHave[$intLooper])
            {
               $bStop=false;
            }
         }

      }
      while ($bStop==false);

      return($intReturnNumber);
   }

   function GenTerm()
   {
      //Get access to the fetch array.
      global $intFetchCode;
      global $strFetchText;
            global $strWords;

      settype($strTerm, "string");

      $intLooper=0;
      //Only a 25% chance of a title

      if ((count($intFetchCode)-1)==0)
      {
               $intWhichFetch = 0;
      }
      else
      {
               $intWhichFetch = rand(0,count($intFetchCode)-1);
      }

      $intArrayHold=array();

      for ($intLooper = 0 ; $intLooper < count($intFetchCode[$intWhichFetch]) ; $intLooper++)
      {
         $intArrayHold[$intLooper]=-1;
      }   

      for ($intLooper = 0 ; $intLooper < count($intFetchCode[$intWhichFetch]) ; $intLooper++)
      {
         $intArrayHold[$intLooper]=GetWord($intFetchCode[$intWhichFetch][$intLooper], $intArrayHold);
      }

      $strTerm=$strFetchText[$intWhichFetch][0];

      for ($intLooper = 0 ; $intLooper < count($intFetchCode[$intWhichFetch]) ; $intLooper++)
      {
         $strTerm .= $strWords[$intArrayHold[$intLooper]];
         $strTerm .= $strFetchText[$intWhichFetch][$intLooper+1];
      }

      return($strTerm);
   }



   if ($selGenCount > 1)
   {
      print("<B>Your steward suggests the following name for your unit:</B><BR>");
   }
   else
   {
      print("<B>Your steward suggests one of the following names for your unit:</B><BR>");
   }

   $aGenHold=array();

   for ($intLooper=0;$intLooper<$selGenCount;$intLooper++)
   {

      $aGenHold[$intLooper]=GenTerm();
   }

   sort($aGenHold);

   for ($intLooper=0;$intLooper<$selGenCount;$intLooper++)
   {
      print($aGenHold[$intLooper]);
      print("<BR>");
   }

?>


Any help is appreciated.
rvec
you got register globals on or something?
$selGenCount is not the same as $_POST['selGenCount ']

if ($selGenCount > 1)
I don't get that, if it is bigger then one it will return one nick, else it will return more?

and why all the globals in the functions?
I don't get why you need all those globals which you use in the function itself only.


settype($strTerm, "string"); what'd you that for?
same for $intLooper=0;

you even forgot to call the first function Confused

this is your script if you cut out all the useless stuff:
Code:
<form action="test.php" method="POST" name="frmControls">
    <p>Number to Generate: <select name="selGenCount" size="1"> <strong>Is Broken at the moment! Only one at a time!</strong>
<?php
$selGenCount = array(1,5,10,15,20,25,30,35,40,45,50);

foreach ($selGenCount as $intLooper){
   if ($_POST['selGenCount']==$intLooper){
      echo "<option value=$intLooper selected>$intLooper</option>";
   } else {
      echo "<option value=$intLooper>$intLooper</option>";
   }
}

echo <<<TEXT
    </select>
   <input type="submit" name="subGenerate" value="Generate"></p>
</form>
<HR>
TEXT;

if ($_POST['selGenCount'] > 1) {
   echo "<B>Your steward suggests one of the following names for your unit:</B><BR>";
} else {
   echo "<B>Your steward suggests the following name for your unit:</B><BR>";
}

for ($intLooper=0;$intLooper<$_POST['selGenCount'];$intLooper++) {
   echo null ."<BR>";
}
?>
Related topics
PHP Tutorials
A PHP problem !
HTML + PHP problem
A php problem
PHP problem...
PHP Problem: Unable to execute ext. commands
PHP Problem
PHP Problem...
php problem
Ton of trouble with Mutiple values in form
Strange PHP Problem
PHP Form Sending problem
PHP Form Processing Problem
Could there be a PhP problem on the server?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.