6 Replies Latest reply on Aug 10, 2006 10:56 AM by Newsgroup_User

    Form and PHP

    pwedding Level 1
      I have a form that I want to submit to an email address. To do this I have attached the page in the action feld of the form tag's properties. The PHP document is very simple because I don't know PHP very at all. here is what is included in it:

      <?
      $name = $_REQUEST['name;]'
      $email = $_REQUEST ['email'];
      $question = $_REQUEST['question']

      mail( "patrick_wedding1@mac.com", "Ask a Librarian – Question", $question, "From: $name, $email")
      ?>

      I have three feilds on the form that I tried to tell this to correspond with:
      Name, Email, and Question

      If there is something wrong with the code, please tell me how to correct it. But the problem is that when I click the submit button in the form after filling out bogus info in the feilds, the actual PHP file is displayed in the browser. How do I fix this?
        • 1. Re: Form and PHP
          Level 7
          Read through:
          http://articles.avenuedesigners.com/index.php?ref=30

          --
          Shane H
          shane@NOSPAMavenuedesigners.com
          http://www.avenuedesigners.com

          =============================================
          Proud GAWDS Member
          http://www.gawds.org/showmember.php?memberid=1495

          Delivering accessible websites to all ...
          =============================================


          "pwedding" <webforumsuser@macromedia.com> wrote in message
          news:eb6f7n$fj4$1@forums.macromedia.com...
          >I have a form that I want to submit to an email address. To do this I have
          > attached the page in the action feld of the form tag's properties. The PHP
          > document is very simple because I don't know PHP very at all. here is what
          > is
          > included in it:
          >
          > <?
          > $name = $_REQUEST['name;]'
          > $email = $_REQUEST ['email'];
          > $question = $_REQUEST['question']
          >
          > mail( "patrick_wedding1@mac.com", "Ask a Librarian ? Question",
          > $question,
          > "From: $name, $email")
          > ?>
          >
          > I have three feilds on the form that I tried to tell this to correspond
          > with:
          > Name, Email, and Question
          >
          > If there is something wrong with the code, please tell me how to correct
          > it.
          > But the problem is that when I click the submit button in the form after
          > filling out bogus info in the feilds, the actual PHP file is displayed in
          > the
          > browser. How do I fix this?
          >


          • 2. Re: Form and PHP
            Level 7
            pwedding wrote:
            > <?
            > $name = $_REQUEST['name;]'
            > $email = $_REQUEST ['email'];
            > $question = $_REQUEST['question']
            >
            > mail( "patrick_wedding1@mac.com", "Ask a Librarian ? Question", $question,
            > "From: $name, $email")
            > ?>

            Several things.

            1. The short PHP tags don't work on all servers. It's more reliable to
            use <?php as the opening tag.
            2. $_REQUEST is less secure than $_POST. It also involves more typing.
            3. Putting $email in the "From" field without subjecting it to rigorous
            validation will turn your site into an open spam relay.

            A simple way to improve your script is like this:

            <?php
            $name = $_POST['name;]'
            $email = $_POST ['email'];
            $question = $_POST['question']
            $message = "$name ($email) sent this question:\n\n$question";

            mail( "patrick_wedding1@mac.com", "Ask a Librarian ? Question", $message);
            ?>

            > the actual PHP file is displayed in the
            > browser. How do I fix this?

            Are you testing locally or on your remote server? If the PHP code is
            being displayed, it sounds as though your server doesn't support PHP.

            --
            David Powers
            Adobe Community Expert
            Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
            http://foundationphp.com/
            • 3. Re: Form and PHP
              pwedding Level 1
              It's local right now. Does it need to be on a live server to work?
              • 4. Re: Form and PHP
                Level 7
                pwedding wrote:
                > It's local right now. Does it need to be on a live server to work?

                PHP scripts need to be parsed by a web server. You can either set up a
                web server on your local computer, or upload to your remote server for
                testing.

                --
                David Powers
                Adobe Community Expert
                Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
                http://foundationphp.com/
                • 5. Re: Form and PHP
                  pwedding Level 1
                  How do i set up the local one?
                  • 6. Re: Form and PHP
                    Level 7
                    pwedding wrote:
                    > How do i set up the local one?

                    The best way is to install Apache, PHP, MySQL, and phpMyAdmin. There are
                    full instructions in my book on how to do it.

                    However, a lot of people prefer to use an all-in-one installer. The most
                    reliable is said to be XAMPP, which you can get from
                    www.apachefriends.org. I don't use XAMPP myself, so can't give you any
                    help with it, but there are plenty of other who could if you run into
                    problems. Apparently, it's a very easy setup, though.

                    --
                    David Powers
                    Adobe Community Expert
                    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
                    http://foundationphp.com/