PHP Web Form Script Problem

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

    PHP Web Form Script Problem

    Hello,

    I have written the following HTML Form:

    <html><head><ti tle>Survey</title></head>
    <body bgcolor="black" text="white" link="#f6b580" vlink="#c0c0ff" >
    <img src="logo.gif" width="324" height="104"alt ="logo.gif (15760
    bytes)"><br><br >

    <table border="0" cellpadding="0" cellspacing="0" width="307" align="left">
    <tr>
    <td background="tab leback.gif" height="25"><p align="center"> <big>Game
    Submission</big><br></td>
    </tr>
    </table>

    <tr>
    <td>
    <br><br><br>
    <FORM METHOD="POST" ACTION="sendgam esub.php"
    enctype="text/plain">

    <b>Game Title</b>:<br> <INPUT TYPE="text" NAME="title" SIZE="35"><br>< br>

    <b>Game Master</b>:<br> <INPUT TYPE="text" NAME="game_mast er"
    SIZE="35"><br>< br>

    <b>E-Mail</b>:<br> <INPUT TYPE="text" NAME="email" SIZE="35"><br>< br>

    <b>Game System</b>:<br> <INPUT TYPE="text" NAME="game_syst em"
    size="35"><br>< br>

    Standard Rules <INPUT TYPE="radio" NAME="rules" VALUE="Standard _Rules">

    Modified Rules <INPUT TYPE="radio" NAME="rules"
    VALUE="Modified _Rules"><br><br >

    <b>Game Type</b>:<br>
    CCG <input type="radio" name="type" value="CCG"><br >
    Miniatures <input type="radio" name="type" value="mini"><b r>
    RPG <input type="radio" name="type" value="rpg"><br >
    LARP <input type="radio" name="type" value="larp"><b r>
    Board <input type="radio" name="type" value="board">< br><br>


    <b>Maturity Rating</b>:<br>
    PG <INPUT TYPE="radio" NAME="rating" VALUE="PG"><br>
    AA <INPUT TYPE="radio" NAME="rating" VALUE="AA"> <br>
    R <INPUT TYPE="radio" NAME="rating" VALUE="R"> <br><br>

    <b>Number of Players</b>:<br> Minimum:<input type="text" name="minplayer s"
    size="2"> Maximum:<input type="text" name="maxplayer s" size="2"><br><b r>

    <b>Game Description:</b><br>
    What is your game about? What sort of characters are <br> available? Brief
    synopsis of plot.
    Limit to 5-6 sentences <br>
    <TEXTAREA NAME="Game_Desc ription" ROWS=6 COLS=35></TEXTAREA> <br><br>

    <b>Anything else we should know about?:</b><br>
    <TEXTAREA NAME="Additiona l_Info" ROWS=6 COLS=35></TEXTAREA> <br><br>

    <INPUT TYPE="image" VALUE="Send" SRC="submit.gif " HEIGHT="33" WIDTH="159"
    BORDER=0 ALT="picture button">

    </td>
    </tr>

    <table border="0" width="307" align="left">
    <tr>
    <td align=center><b r><br><h6> <a href="main.html ">Home</a> | <a
    href="location. html">Location</a> | <a href="games.htm l">Games</a> | <a
    href="register. html">Register</a> | <a href="survey.ht ml">Survey</a> | <a
    href="contact.h tml">Contact</a>
    </h6>
    <h6> <br> </td>
    </tr>
    </table></div></body></FORM></html>


    I have also written the following PHP script:

    <?php
    $to = myemail@uoguelp h.ca;
    $title = ($_POST['title']);
    $game_master = ($_POST['game_master']);
    $email = ($_POST['email']);
    $game_system = ($_POST['game_system']);
    $rules = ($_POST['rules']);
    $type = ($_POST['type']);
    $rating = ($_POST['rating']);
    $minplayers = ($_POST['minplayers']);
    $maxplayers = ($_POST['maxplayers']);
    $Game_Descripti on = ($_POST['Game_Descripti on']);
    $Additional_Inf o = ($_POST['Additional_Inf o']);


    $sub = "Game Submission";
    $headers .= "From: " .$game_master." <".$email.">\n" ;
    $headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
    $mes = "Title: ".$title."
    Game Master: ".$game_master. "
    E-Mail: ".$email."
    Game System: ".$game_system. "
    Rules: ".$rules."
    Type: ".$type."
    Rating: ".$rating."
    Min. Players: ".$minplaye rs."
    Max. Players: ".$maxplaye rs."
    Game Description: ".$Game_Descrip tion."
    Additional Info: ".$Additional_I nfo."";

    mail($to, $sub, $mes, $headers);
    ?>

    The script isn't working properly. It sends the email but there is no data
    in the email. For instance it doesn't send the Game Master or the Rating.
    I can't seem to see where the problem is coming from. Can somebody point
    out the problem. From what I can tell there doesn't seem to be any syntax
    errors. I am fairly new to PHP so I could be mistaken.

    Regards,
    Jeff


  • News Me

    #2
    Re: PHP Web Form Script Problem

    Jeff Dunnett wrote:[color=blue]
    > Hello,
    >
    > I have written the following HTML Form:
    >
    > <html><head><ti tle>Survey</title></head>
    > <body bgcolor="black" text="white" link="#f6b580" vlink="#c0c0ff" >
    > <img src="logo.gif" width="324" height="104"alt ="logo.gif (15760
    > bytes)"><br><br >
    >
    > <table border="0" cellpadding="0" cellspacing="0" width="307" align="left">
    > <tr>
    > <td background="tab leback.gif" height="25"><p align="center"> <big>Game
    > Submission</big><br></td>
    > </tr>
    > </table>
    >
    > <tr>
    > <td>
    > <br><br><br>
    > <FORM METHOD="POST" ACTION="sendgam esub.php"
    > enctype="text/plain">
    >
    > <b>Game Title</b>:<br> <INPUT TYPE="text" NAME="title" SIZE="35"><br>< br>
    >
    > <b>Game Master</b>:<br> <INPUT TYPE="text" NAME="game_mast er"
    > SIZE="35"><br>< br>
    >
    > <b>E-Mail</b>:<br> <INPUT TYPE="text" NAME="email" SIZE="35"><br>< br>
    >
    > <b>Game System</b>:<br> <INPUT TYPE="text" NAME="game_syst em"
    > size="35"><br>< br>
    >
    > Standard Rules <INPUT TYPE="radio" NAME="rules" VALUE="Standard _Rules">
    >
    > Modified Rules <INPUT TYPE="radio" NAME="rules"
    > VALUE="Modified _Rules"><br><br >
    >
    > <b>Game Type</b>:<br>
    > CCG <input type="radio" name="type" value="CCG"><br >
    > Miniatures <input type="radio" name="type" value="mini"><b r>
    > RPG <input type="radio" name="type" value="rpg"><br >
    > LARP <input type="radio" name="type" value="larp"><b r>
    > Board <input type="radio" name="type" value="board">< br><br>
    >
    >
    > <b>Maturity Rating</b>:<br>
    > PG <INPUT TYPE="radio" NAME="rating" VALUE="PG"><br>
    > AA <INPUT TYPE="radio" NAME="rating" VALUE="AA"> <br>
    > R <INPUT TYPE="radio" NAME="rating" VALUE="R"> <br><br>
    >
    > <b>Number of Players</b>:<br> Minimum:<input type="text" name="minplayer s"
    > size="2"> Maximum:<input type="text" name="maxplayer s" size="2"><br><b r>
    >
    > <b>Game Description:</b><br>
    > What is your game about? What sort of characters are <br> available? Brief
    > synopsis of plot.
    > Limit to 5-6 sentences <br>
    > <TEXTAREA NAME="Game_Desc ription" ROWS=6 COLS=35></TEXTAREA> <br><br>
    >
    > <b>Anything else we should know about?:</b><br>
    > <TEXTAREA NAME="Additiona l_Info" ROWS=6 COLS=35></TEXTAREA> <br><br>
    >
    > <INPUT TYPE="image" VALUE="Send" SRC="submit.gif " HEIGHT="33" WIDTH="159"
    > BORDER=0 ALT="picture button">
    >
    > </td>
    > </tr>
    >
    > <table border="0" width="307" align="left">
    > <tr>
    > <td align=center><b r><br><h6> <a href="main.html ">Home</a> | <a
    > href="location. html">Location</a> | <a href="games.htm l">Games</a> | <a
    > href="register. html">Register</a> | <a href="survey.ht ml">Survey</a> | <a
    > href="contact.h tml">Contact</a>
    > </h6>
    > <h6> <br> </td>
    > </tr>
    > </table></div></body></FORM></html>
    >
    >
    > I have also written the following PHP script:
    >
    > <?php
    > $to = myemail@uoguelp h.ca;
    > $title = ($_POST['title']);
    > $game_master = ($_POST['game_master']);
    > $email = ($_POST['email']);
    > $game_system = ($_POST['game_system']);
    > $rules = ($_POST['rules']);
    > $type = ($_POST['type']);
    > $rating = ($_POST['rating']);
    > $minplayers = ($_POST['minplayers']);
    > $maxplayers = ($_POST['maxplayers']);
    > $Game_Descripti on = ($_POST['Game_Descripti on']);
    > $Additional_Inf o = ($_POST['Additional_Inf o']);
    >
    >
    > $sub = "Game Submission";
    > $headers .= "From: " .$game_master." <".$email.">\n" ;
    > $headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
    > $mes = "Title: ".$title."
    > Game Master: ".$game_master. "
    > E-Mail: ".$email."
    > Game System: ".$game_system. "
    > Rules: ".$rules."
    > Type: ".$type."
    > Rating: ".$rating."
    > Min. Players: ".$minplaye rs."
    > Max. Players: ".$maxplaye rs."
    > Game Description: ".$Game_Descrip tion."
    > Additional Info: ".$Additional_I nfo."";
    >
    > mail($to, $sub, $mes, $headers);
    > ?>
    >
    > The script isn't working properly. It sends the email but there is no data
    > in the email. For instance it doesn't send the Game Master or the Rating.
    > I can't seem to see where the problem is coming from. Can somebody point
    > out the problem. From what I can tell there doesn't seem to be any syntax
    > errors. I am fairly new to PHP so I could be mistaken.
    >
    > Regards,
    > Jeff
    >
    >[/color]

    Not that it has anything to do with the problem, but you should be
    single-quoting the email address:

    $to = 'myemail@uoguel ph.ca';

    In fact, with PHP 5, the script aborted with this error:

    PHP Parse error: syntax error, unexpected '@' in
    D:\\htdocs\\sen dgamesub.php on line 2, referer: http://localhost/test.html


    You don't need the parens around all these:

    $var = $_POST[...];


    As for the empty content, it started working for me when I dropped the
    'enctype="text/plain"' from the <form ...> element.


    You should consider using an HTML validator. Firefox was a Tidy
    extensions that lists 15 warnings for the page as listed above.

    NM

    --
    convert UPPERCASE NUMBER to a numeral to reply

    Comment

    • Jeff Dunnett

      #3
      Re: PHP Web Form Script Problem

      NM,

      Thank you very much for your help. My problems are solved.

      Regards,
      Jeff


      Comment

      • Geoff Berrow

        #4
        Re: PHP Web Form Script Problem

        I noticed that Message-ID: <111de8lq2upor4 3@corp.supernew s.com> from
        News Me contained the following:
        [color=blue]
        >You don't need the parens around all these:
        >
        >$var = $_POST[...];[/color]

        In fact he could have saved the bother of writing those lines at all
        e.g.

        $headers .= "From: " .$_POST['game_master']."<".$_POST['email'].">\n";

        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • Philip Ronan

          #5
          Re: PHP Web Form Script Problem

          Geoff Berrow wrote:
          [color=blue]
          > I noticed that Message-ID: <111de8lq2upor4 3@corp.supernew s.com> from
          > News Me contained the following:
          >[color=green]
          >> You don't need the parens around all these:
          >>
          >> $var = $_POST[...];[/color]
          >
          > In fact he could have saved the bother of writing those lines at all
          > e.g.
          >
          > $headers .= "From: " .$_POST['game_master']."<".$_POST['email'].">\n";[/color]

          NO!!!

          Never *ever* put unvalidated content into your email headers.

          Suppose I posted some data to your site with "game_maste r" set to something
          like this:

          nobody@nowhere. com%0ATo:%20geo ff...like spam.org%0ASubject:%20V 14GR4...

          Insecure scripts like yours make things really easy for spammers. Think
          about it.

          --
          phil [dot] ronan @ virgin [dot] net



          Comment

          • Toby Inkster

            #6
            Re: PHP Web Form Script Problem

            Geoff Berrow wrote:
            [color=blue]
            > $headers .= "From: " .$_POST['game_master']."<".$_POST['email'].">\n";[/color]

            Ugly.

            Better:
            $headers .= "From: {$_POST[game_master]} <{$_POST[email]}>\n";

            --
            Toby A Inkster BSc (Hons) ARCS
            Contact Me ~ http://tobyinkster.co. uk/contact

            Comment

            • Geoff Berrow

              #7
              Re: PHP Web Form Script Problem

              I noticed that Message-ID:
              <pan.2005.02.19 .14.45.11.43013 8@tobyinkster.c o.uk> from Toby Inkster
              contained the following:
              [color=blue][color=green]
              >> $headers .= "From: " .$_POST['game_master']."<".$_POST['email'].">\n";[/color]
              >
              >Ugly.
              >
              >Better:
              >$headers .= "From: {$_POST[game_master]} <{$_POST[email]}>\n";[/color]

              The OP had already used the concatenation operator and so was familiar
              with it. When I am teaching PHP, I find my students struggle with
              syntax. Reducing the amount of things to remember helps.
              --
              Geoff Berrow (put thecat out to email)
              It's only Usenet, no one dies.
              My opinions, not the committee's, mine.
              Simple RFDs http://www.ckdog.co.uk/rfdmaker/

              Comment

              Working...