0

I am a beginner in PHP. I am stuck on something that seems really easy. I built a website, and there is a page in the website where people can send me e-mail through a form. The problem is, I think form seems to fail creating $POST_['name']. Just read the codes and you'll understand what im saying.

<form action="?" method="post">
            <div id="right">
                <label for="name"> <input type="text" class="kutu" name="name" ></label><br />
                <label for="email"> <input type="email" class="kutu" name="email" ></label><br />
                <label for="subject"> <input type="text" class="kutu" name="subject" ></label><br />
            </div>
            <div id="left">
                <p>Name: </p>
                <p>Your Email Adress: </p>
                <p>Subject: </p>
            </div>

            <div id="bottom">
                <p>Your Message:</p><br />
                <label for="message"><textarea name="message" rows="3" cols="60"> </textarea></label>
            </div>
                <input type="submit" id="tus" value="submit">


</form>

And here is the PHP

if (isset($POST_['name'])) {
    $email = $POST_['email'];
    $subject = $POST_['subject'];
    $message = "From: " . $POST_['name'] . ", " . $POST_['email'] . "\n Message: " . $POST_['message'];
    try {
        mail("myEmailAdress@gmail.com", $subject, $message, " ");
        unset($POST_['name']);
        header("Location: success.php");

    }
    catch (PDOException $e)
    {

        include 'index.html';
        exit();
    }
    exit();
} 
include 'contact2.php';

When i submit my form, it takes me to contact2.php again, which tells me that POST_['name'] was never created in the first place.

  • 1
    @loko Imho it gets interpreted as an empty query string, so the form is basically sent to the current page. – nietonfir Oct 09 '13 at 20:42
  • @nietonfir Aha never knew that. So I learned something extra today. – Loko Oct 09 '13 at 20:43
  • 1
    @loko Normally the hash (`#`) is used for same-page form submission, but you can ommit it or leave it empty since HTML5. See http://stackoverflow.com/a/9401608/838733 – nietonfir Oct 09 '13 at 20:53

1 Answers1

3

The variable name is $_POST, not $POST_. See http://php.net/EN/reserved.variables.post.php

nietonfir
  • 4,797
  • 6
  • 31
  • 43
  • @DimaGoltsman Did you even bother to read the question or did you just flag the answer in the review queue? Sometimes short answers are just that… – nietonfir Sep 28 '14 at 13:43