SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Threaded View

  1. #1
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to sanitize data but receiving notice - undefined index

    Hello everyone,

    I'm trying to sanitize some data in a form.

    The code in the contact form includes the following:

    HTML Code:
    <form name="form1" method="post" action="form-email.php">
        <input type="text" name="name" value="<?php echo $_POST['name']; ?>" size="50" 
        <input type="submit" name="Submit" />
    </form>
    The code in form-email.php includes:

    PHP Code:
    <?php
        
    if (isset($_POST['Submit'])) {

            if (
    $_POST['name'] != "") {
                
    $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
                if (
    $_POST['name'] == "") {
                    
    $errors .= 'Please enter a valid name.<br/><br/>';
                }
            } else {
                
    $errors .= 'Please enter your name.<br/>';
            }
        }
    ?>
    When I open the page which includes the contact form, I receive a notice:
    Undefined index: name in C:\wamp\www\site1\contact-us.php on line 11


    What does this mean?


    Please help – thank you!
    Last edited by cpradio; Jul 10, 2013 at 05:49. Reason: Added php tags and html tags


Bookmarks

Posting Permissions

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