Fork me on GitHub

Help with writing a small module.  Bottom

  • I am trying to write a small module to calculate the weight of a bass from it's length and girth. I have written one, but it does not work properly. The link to what I have done is here.....http://www.e-bassangler.com/Weight+main.html

    The problem is when you submit a length and girth I get the same page. How can I make this work? Here is the code that I am using.

    Code

    ?php
    if (!defined("LOADED_AS_MODULE")) {
        die ("You can't access this file directly...");
    }
    global $pnconfig;
    $pntable = pnDBGetTables();
    $ModName = basename( dirname( __file__ ) );
    //End PNphpBB2 Module

    define('IN_PHPBB', true);
    // Begin PNphpBB2 Module
    $phpbb_root_path = './modules/PNphpBB2/';
    //End PNphpBB2 Module
    include($phpbb_root_path . 'extension.inc');
    include($phpbb_root_path . 'common.'.$phpEx);
    include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
    include($phpbb_root_path . 'includes/functions_search.'.$phpEx);

    // Start session management
    $userdata = session_pagestart($user_ip, PAGE_SEARCH);
    init_userprefs($userdata);
    include ("header.php");
    if (empty($girth)) {
        print "This page is still under construction";
        print "<br><br><br>";
        print "<h4>Want to know the weight of a lunker bass you caught, but left your scale at home?</h4>";
        print "<h5>Well you are in luck...If you remembered to measure the length and girth!</h5>";
        print <<<HERE
        <br>
        <br>
        <form>
            Enter the length:
        <input type = "text"
               name = "length"><br>
        Enter the girth:
        <input type = "text"
               name = "girth">
               <br>
        <input type = "submit">

        </form>


    HERE;

    } else {
        $weight = ($length*($girth*$girth))/927;
        print "<br><br><br>";
        print "Your Bass weighed approximately $weight lbs";
    } //end
    // include footer junk

    include("footer.php");
    ?>


    Oh, also I would like to truncate the weight at 2 decimal places. I am very new to PHP and have not learned how to do this yet.

    Thanks for the help
    James
    www.e-bassangler.com
  • You could likely do this easier with Javascript, perhaps in a HTML block...

    However if you do not have register_globals set to on in your PHP setup, the $girth variable will not tbe recognized...

    You should use $_GET['girth'] or $_POST['girth'] instead - depending on the METHOD of your
    , which you neglected to add in...

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • I would do this with Javascript, but I know nothing about it. Anyone want to help me out?

    James
  • Not really related to Postnuke, you'd be better off checking out some Javascript sites and/or modding some Javascript calculators...

    At any rate if you follow the advice in the prior post, you can likely get your module working - just thought the JSCRIPT would be a bit slicker ;)

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • Thanks a million.....I am going to see if I can get it going today.

    James
  • Don't forget to add method (GET OR POST) and action (the name of this file) to your FORM tag, if you're going with the module option...

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • Ok, I got the module to work, now how can I truncate the weight to 2 decimal places?
  • 0 users

This list is based on users active over the last 60 minutes.