Hello recently some of you gave me help with my php form.
Well I have altered it slightly using a book and it has shown me
how to incorporate the php into itself.

So the form should work without an external php page

Could someone tell me if this is correct, I have attached the webpage in .txt format.

Thank you.

Dani AI

Generated

Embedding the form processor in the same file is a normal, safe pattern when done carefully. your approach is fine; was right to call out case sensitivity — the HTML name attributes become the exact keys PHP reads from the request, so spelling and case must match exactly.

Keep this short checklist in mind:

  • Only run processing when the request method is POST.
  • Make the form field name values and the keys you read in PHP match exactly.
  • Validate inputs (for example, use PHP filter functions for emails) and sanitize or escape before output (htmlspecialchars) to avoid XSS.
  • Use prepared statements for any database work to prevent SQL injection.
  • After successful processing, do a redirect (Post/Redirect/Get) to avoid form resubmission on refresh.

A minimal safe pattern (illustrative) looks like this:

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $visitor = trim((string) filter_input(INPUT_POST, 'visitor_name', FILTER_DEFAULT));
    $email = filter_input(INPUT_POST, 'email_address', FILTER_VALIDATE_EMAIL);
    $safe = htmlspecialchars($visitor, ENT_QUOTES, 'UTF-8');
    // validate and process, then redirect
}

For debugging, enable full error reporting during development and inspect the POST payload (browser devtools or var_dump($_POST)) to confirm the keys. See the PHP docs for $_POST and filter_input for details: PHP $_POST manual page and .

Recommended Answers

All 2 Replies

Very close. Remember, variables are case sensitive.
<input type="text" name="username" maxlength="12"/>
Then in the php you have:
$Username = $_POST["Username"];
Should be:
$Username = $_POST["username"];
The same goes for email, wing, and comment. Looks like your getting the hang of it though.

So when I change the case sensativity so that they are equal, it should work.

Taking into account that this form is itself the php as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.