Something not right...

Discussion in 'PHP' started by greenstar91, May 16, 2008.

  1. #1
    I have a basic form and want the results to display on the same page. I have come up with some code below but it does not work. Can someone help?

    <html>
    <body>
    
    <form action="form.php" method="post">
    No. of Characters used: <input type="text" name="char" /><br><br>
    Combination size: <input type="text" name="size" />
    <input type="hidden" name="send" value="check">
    <input type="submit" />
    </form>
    
    </body>
    </html>
    
    <?php
    
    
    $send = $_GET["send"];
    
    
    if (!(isset($send))) {
    	$send = $_POST["send"];
    }
    $characters = $_POST["char"];
    $charlength = strlen($characters);
    $combinations = $_POST["size"];
    $possibilities = pow($charlength,$combinations);
    
    
    
    if ($send=="check") {
    echo "Characters = " $charlength;
    echo "<br>";
    echo "Combination Size =  $combinations.";
    echo "<br>";
    echo "Combinations = $possibilities.";}
    
    ?>
    
    
    PHP:
    Basically it is a script for determining how many possible combinations (including repeats) you can have when you have an X amount of possible characters (numbers or letters or other stuff) and Y digits long.
     
    greenstar91, May 16, 2008 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    do you get an error? what about it does not work
     
    crath, May 16, 2008 IP
  3. greenstar91

    greenstar91 Guest

    Messages:
    221
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    echo "Characters = " $charlength;
    echo "<br>";
    echo "Combination Size =  $combinations.";
    echo "<br>";
    echo "Combinations = $possibilities.";}
    
    PHP:
    The first part just displays what I entered into the 'no. of characters used'

    The other two parts just display '1'.

    I have a working example for a form with two separate files here.

    This shows how I want the script to work.

    Thanks
     
    greenstar91, May 16, 2008 IP
  4. Cybernaut

    Cybernaut Peon

    Messages:
    408
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    In your code, thats not actually "No. of Characters used:". Its just "Characters" as in example page. You need need to put the actual characters like "abcxyz" in first field and code is counting the "number of characters used" itself. Theres nothing wrong with the wrong, except:

    echo "Characters = " $charlength;

    should be:

    echo "Characters = " . $charlength;
    or
    echo "Characters = ", $charlength;
    or
    echo "Characters = $charlength";
     
    Cybernaut, May 16, 2008 IP
  5. greenstar91

    greenstar91 Guest

    Messages:
    221
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Cybernaut Thank you for your reply. I have now managed to get the script working. I plan to release it in the freebie section soon when I have put a lot more features on it.
     
    greenstar91, May 17, 2008 IP