Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4016618
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:45:42+00:00 2026-05-20T09:45:42+00:00

I created a sample form and code below to illustrate. I know i can

  • 0

I created a sample form and code below to illustrate. I know i can turn notices off in php but would rather fix the problem rather than ignore it.

When i create forms i do like what i have posted below, obviously this is just a sample with no sanitization etc.

I sort of know why i get the Notice: Undefined Variable which i know sounds dumb but not sure what’s the easiest and correct way to solve it.

Could one of you great people out there show me how to stop this notice appearing?

It’s only now i realised i did not have all error reporting on in WAMP and i have created allot of forms and i really don’t want to be doing loads of re-editing code to fix it, hence i’m looking for a good, simple solution to solve it so i can go into all my forms and sort it once and for all.

<?php
// check if form has been submitted
if(isset($_POST['submit'])){

    // fetch form data
    $name = $_POST['name']; 
    $username = $_POST['username']; 
    $email = $_POST['email'];

    // check form fields
    if(empty($name)){
        $error .= 'Enter name <br />';
    }
    if(empty($username)){
        $error .= 'Enter username <br />';
    }
    if(empty($email)){
        $error .= 'Enter email <br />';
    }

    // check if errors exist
    if(isset($error)){
        echo $error;    
    } else {
        // process form as normal   
    }
}
?>

<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">

<label for="name">Name:</label>
<input type="text" name="name" value="<?php if(isset($name)) echo $name; ?>" />

<label for="name">Username:</label>
<input type="text" name="username" value="<?php if(isset($username)) echo $username; ?>" />

<label for="email">Email:</label>
<input type="text" name="email" value="<?php if(isset($email)) echo $email; ?>" />

<input type="submit" name="submit" value="Send" />

</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:45:43+00:00Added an answer on May 20, 2026 at 9:45 am

    You are right, the problem is the first string concatenation $error .= "something", because $error does not exist before.

    Easy fix: Initialise $error with an empty string and use !empty($error) instead of isset($empty).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is sample code to create a radio button element with Yes/No options in
I am very new to ajax and jquery but I know some php. I
I am new to ADO.net. I actually created a sample database and a sample
I'm trying to add a strongly-typed view to the sample app that's created when
So I'm a newbie to TDD, and I successfully created a nice little sample
Just thinking about the best way to build an Order form that would (from
I have a pretty simple HTML form where users can enter in information about
i am new to this FCKeditor,i am using below mentioned code , i am
I have created a simple form that emails the entered values to a designated
I do primarily web stuff, but I've been playingnaround with a simple windws form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.