saving data from a form into a seperate .html file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian

    saving data from a form into a seperate .html file

    I wrote this script here but I cannot get the script to save to the
    correct month.html. Can someone tell me what is wrong with this code?

    <html>
    <head>
    <title>Monthl y Bills</title>
    </head>
    <body>
    <center><font size="4">Total Monthly Bills</font>
    <form action="billcal culation.php" method="POST">
    <br>
    <select name="months">
    <option value="January" name="month">Ja nuary</option>
    <option value="February " name="month">Fe bruary</option>
    <option value="March" name="month">Ma rch</option>
    <option value="April" name="month">Ap ril</option>
    <option value="May" name="month">Ma y</option>
    <option value="June" name="month">Ju ne</option>
    <option value="July" name="month">Ju ly</option>
    <option value="August" name="month">Au gust</option>
    <option value="Septembe r" name="month">Se ptember</option>
    <option value="October" name="month">Oc tober</option>
    <option value="November " name="month">No vember</option>
    <option value="December " name="month">De cember</option>
    </select><br><br>
    <table border="0">
    <td>Rent:</td><td><input type="text" name="apartment _rent"
    size="5"></td><tr>
    <td>Water & Sewage</td><td><input type="text" name="water_sew age"
    size="5"></td><tr>
    <td>Cell Phone:</td><td><input type="text" name="cell_phon e"
    size="5"></td><tr>
    <td>Cable & Internet:</td><td><input type="text" name="cable_int ernet"
    size="5"></td><tr>
    <td><center><in put type="submit" name="submit"
    action="submit" ></center></td><td><input type="reset" name="reset"
    action="reset"> </td></table>
    </center></form>
    <center><font size="4">Monthl y Bills for 2005-2006</font><br><br>

    <?php

    $fp = fopen("$_POST['month'] . ".html","a+ ");
    $output = print "TEST";



    $apartment_rent = $_POST['apartment_rent '];
    $water_sewage = $_POST['water_sewage'];
    $cell_phone = $_POST['cell_phone'];
    $cable_internet = $_POST['cable_internet '];

    $total_monthly_ bill = $apartment_rent + $water_sewage + $cell_phone +
    $cable_internet ;

    print "Bills for <b>{$_POST['months']}</b><br>";
    print "Apartment rent: $apartment_rent <br>";
    print "Water and sewage: $water_sewage <br>";
    print "Verizon cell phone bill: $cell_phone <br>";
    print "Time Warner cable bill: $cable_internet <br>";
    print "Total monthly payment: $total_monthly_ bill <br>";
    ?>
    </body>
    </html>

  • Oli Filth

    #2
    Re: saving data from a form into a seperate .html file

    Brian said the following on 30/11/2005 20:01:[color=blue]
    > I wrote this script here but I cannot get the script to save to the
    > correct month.html. Can someone tell me what is wrong with this code?
    >[/color]

    <...SNIP CODE...>

    Did you try turning error reporting on?

    --
    Oli

    Comment

    • Oli Filth

      #3
      Re: saving data from a form into a seperate .html file

      Brian said the following on 30/11/2005 20:01:[color=blue]
      > I wrote this script here but I cannot get the script to save to the
      > correct month.html. Can someone tell me what is wrong with this code?
      >[/color]
      <...SNIP CODE...>

      Did you try turning error reporting on?

      --
      Oli

      Comment

      • vdP

        #4
        Re: saving data from a form into a seperate .html file

        Brian wrote:[color=blue]
        > I wrote this script here but I cannot get the script to save to the
        > correct month.html. Can someone tell me what is wrong with this code?
        >[/color]
        <SNIP CODE>[color=blue]
        > <?php
        >
        > $fp = fopen("$_POST['month'] . ".html","a+ ");[/color]

        There are five quotes(") here. I can hardly imagine that is right.

        vdP

        Comment

        • IWP506@gmail.com

          #5
          Re: saving data from a form into a seperate .html file


          vdP wrote:[color=blue]
          > Brian wrote:[color=green]
          > > I wrote this script here but I cannot get the script to save to the
          > > correct month.html. Can someone tell me what is wrong with this code?
          > >[/color]
          > <SNIP CODE>[color=green]
          > > <?php
          > >
          > > $fp = fopen("$_POST['month'] . ".html","a+ ");[/color]
          >
          > There are five quotes(") here. I can hardly imagine that is right.
          >
          > vdP[/color]

          Yep, make it:

          $fp = fopen($_POST['month'] . ".html","a+ ");

          iwp506

          Comment

          • Brian

            #6
            Re: saving data from a form into a seperate .html file

            ok that worked i changed the code a little bit, now I'm getting an
            error like this:
            Fatal error: Function name must be a string in
            /usr/local/www/billcalculation .php on line 36

            $fp = fopen($_POST['month'] . ".html","a+ ");
            $fwrite ($fp, $data);
            fclose($fp);

            $data = print "Apartment: $apartment_rent "; //want it to print that to
            the new .html file.
            thats what I have, why am I getting this error?

            Comment

            • Steve

              #7
              Re: saving data from a form into a seperate .html file

              [color=blue]
              > Fatal error: Function name must be a string in
              > /usr/local/www/billcalculation .php on line 36
              >
              > $fp = fopen($_POST['month'] . ".html","a+ ");
              > $fwrite ($fp, $data);
              > fclose($fp);[/color]
              [color=blue]
              > $data = print "Apartment: $apartment_rent "; //want it to print that to
              > the new .html file.[/color]

              This is not a PHP problem.

              ---
              Steve

              Comment

              • vdP

                #8
                Re: saving data from a form into a seperate .html file

                Brian wrote:[color=blue]
                > ok that worked i changed the code a little bit, now I'm getting an
                > error like this:
                > Fatal error: Function name must be a string in
                > /usr/local/www/billcalculation .php on line 36
                >
                > $fp = fopen($_POST['month'] . ".html","a+ ");
                > $fwrite ($fp, $data);
                > fclose($fp);
                >
                > $data = print "Apartment: $apartment_rent "; //want it to print that to
                > the new .html file.
                > thats what I have, why am I getting this error?
                >[/color]

                A few things:
                1. Read http://www.safalra.com/special/googlegroupsreply/ about how to
                use Google groups.
                2. I hope you defined $data before you try to write it to the new html-file.
                3. (By far the most important point.) The print function outputs the
                given string as normal html, i.e. you will see it in your browser if you
                open billcalculation .php . The statement above assigns the result of the
                print function (which is always the integer 1) to $data. Hence, the
                number 1 should be written to the new html-file. Instead use
                $data="Apartmen t: $apartment_rent ";
                $fwrite ($fp, $data);
                (And if you want to show it in billcalculation .php as well, throw in
                print $data; )

                Hope this helps.

                vdP

                Comment

                Working...