Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2005
    Location
    Burlington, VT
    Posts
    181

    Can you tell me whats wrong with this code?

    <form method="post" action="contact1.php">
    Subject:<input type="text" name="subject"><br>
    Message:<br>
    <textarea name="body" cols="50" rows="12"></textarea>
    <input type="submit" value="Send">
    </form>
    <?php
    //if submit has value
    if (isset($_POST['submit'])) {
    //send mail
    mail ('colin.urban@gmail.com',$_POST['subject'],$_POST['body']);
    } else {
    die ();
    }
    ?>
    Last edited by -=Superfly=-; 12-04-2005 at 12:28 PM.

  2. #2
    Join Date
    Oct 2005
    Posts
    3
    I've had problems with the post method recently, and I found toying with it works. It also might be your mail function, but I'm not familar with the mail function. Might try the following

    if (isset($_POST["submit"])) {

    or

    if (isset($_POST["body"]) AND isset($_POST["subject"]){

    Trying mixing up the ' and ", sometimes that solves my problem. Also, before doing the if statement on the second page, try putting "print_r($_POST);" and //ing out the rest. That will print the $_POST superglobal array and tell you if data is being passed from the form page or if your error is there. I wrote a news system (admin can post a news item and users can post comments) a while ago and has SOOOOO many post problems. Good luck. Let me know if any of that works.

  3. #3
    Join Date
    Oct 2003
    Location
    Netherlands
    Posts
    125
    dumping the $_POST variable is a very good thing to do when you are stuck in such a situation. dumping vars to debug is always handy.

    If you would dump the $_POST var you would see that it has no "submit" index.

    There fore isset($_POST["submit"]) will return false.

    You have to give your submit button a name in order to post it as a value together with the other form data.

    So do:
    <input type="submit" name="submit" value="Send">

    This makes the variable 'submit' wil be send with the value 'Send';
    So:
    $_POST['submit'] == "Send"; //true

  4. #4
    Join Date
    Jul 2005
    Location
    Burlington, VT
    Posts
    181
    ok guys, thanks

  5. #5
    Join Date
    Mar 2002
    Location
    Denmark
    Posts
    684
    dumb question to ask but contact1.php is the page where all this code is located right? So the page submits to itself?
    you could use $_SERVER['PHP_SELF'] as the action then...
    anyway.. yeah it might be your mail function... try also placing a value in die();
    This way a message will be shown if isset($_POST['submit']) fails..

    might also wanna check out
    http://dk2.php.net/manual/en/language.constants.php

    I am not sure if isset produces the correct outcome with superglobals...
    http://dk2.php.net/manual/en/function.isset.php

    Well hope this helps.. a little... =)
    ~Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •